Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unified patch for namespaced tags #261

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions karax/karax.nim
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,15 @@ proc toDom*(n: VNode; useAttachedNode: bool; kxi: KaraxInstance = nil): Node =
result = toDom(x.expanded, useAttachedNode, kxi)
attach n
return result
else:
result = document.createElement(toTag[n.kind])
else: # we are dealing with fundamental tags at this point, and not nim components/functions
if (svgElements*needingNamespace).contains(n.kind):
result = document.createElementNS(svgNamespace,toTag[n.kind]) #svg top-level elements need to be declared with a namespace
#we apply a default so that users can just treat it like html in the DSL while learning

elif (mathElements*needingNamespace).contains(n.kind): #mathML needs a similar treatment as svg
result = document.createElementNS(mathNamespace,toTag[n.kind])
else:
result = document.createElement(toTag[n.kind])
attach n
for k in n:
appendChild(result, toDom(k, useAttachedNode, kxi))
Expand Down
11 changes: 11 additions & 0 deletions karax/vdom.nim
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ type
const
selfClosing = {area, base, br, col, embed, hr, img, input,
link, meta, param, source, track, wbr}

const
svgElements* = {animate..view}
mathElements* = {maction..semantics}
needingNamespace* = {svg,math}

var
svgNamespace* = "http://www.w3.org/2000/svg"
mathNamespace* = "http://www.w3.org/1998/Math/MathML"
#global var settings: defaults are already set up, but may be adjusted in one shot for the user's entire project


type
EventKind* {.pure.} = enum ## The events supported by the virtual DOM.
Expand Down