Skip to content

Commit

Permalink
use otherTag
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Nov 30, 2022
1 parent 382d1f9 commit cac33f6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
3 changes: 0 additions & 3 deletions .gitattributes

This file was deleted.

2 changes: 1 addition & 1 deletion marggers.nimble
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "0.3.2"
version = "0.3.3"
author = "metagn"
description = "markdown dialect"
license = "MIT"
Expand Down
16 changes: 9 additions & 7 deletions src/marggers/element.nim
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ type
sup, sub, em, strong, pre, code, u, s,
img, input, a,
video, audio,
#otherTag, text
otherTag
#text

MarggersElement* {.acyclic.} = ref object
## An individual node.
Expand All @@ -29,15 +30,15 @@ type
tag*: KnownTags
## The tag of an HTML element.
##
## If unknown (equal to `noTag`), the `tag` attribute is used.
## An unknown tag can also indicate having no ending tag
## If equal to `otherTag`, the `tag` attribute is used.
## Such elements can also indicate having no ending tag
## with the `emptyTag` attribute.
attrs*: OrderedTable[NativeString, NativeString]
## Attributes of an HTML element.
content*: seq[MarggersElement]
## Inner HTML elements of an HTML element.

const EmptyTags* = {noTag, br, img, input}
const EmptyTags* = {noTag, br, img, input, otherTag}

when defined(js):
func isEmpty*(tag: KnownTags): bool {.inline.} =
Expand Down Expand Up @@ -133,10 +134,12 @@ func toNativeString*(elem: MarggersElement): NativeString =
else:
var empty = elem.tag.isEmpty
var tag: NativeString
if unlikely(elem.tag == noTag):
case elem.tag
of noTag: discard # tag stays empty
of otherTag:
if elem.hasAttr("tag"):
tag = elem.attr("tag")
empty = not elem.hasAttr("emptyTag")
empty = elem.hasAttr("emptyTag")
else:
when NativeString is string:
tag = $elem.tag
Expand All @@ -153,7 +156,6 @@ func toNativeString*(elem: MarggersElement): NativeString =
result.add('=')
result.addQuoted(attrValue)
else:

result.add(cstring "=\"")
result.add(attrValue)
result.add("\"")
Expand Down

0 comments on commit cac33f6

Please sign in to comment.