Skip to content

Commit

Permalink
feature: Inject block attributes into labelled list text.
Browse files Browse the repository at this point in the history
  • Loading branch information
srackham committed Jan 31, 2020
1 parent 9308384 commit 503e98f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
13 changes: 7 additions & 6 deletions src/rimu/blockattributes.py
Expand Up @@ -70,7 +70,7 @@ def parse(attrs: str) -> bool:
return True


def injectHtmlAttributes(tag: str) -> str:
def injectHtmlAttributes(tag: str, consume: bool=True) -> str:
'''Inject HTML attributes into the HTML `tag` and return result.
Consume HTML attributes unless the 'tag' argument is blank.'''
global classes, id, css, attributes, opts, ids
Expand Down Expand Up @@ -114,11 +114,12 @@ def injectHtmlAttributes(tag: str) -> str:
before = result[:len(match[0])]
after = result[len(match[0]):]
result = before + ' ' + attrs + after
# Consume the attributes.
classes = ''
id = ''
css = ''
attributes = ''
if consume:
# Consume the attributes.
classes = ''
id = ''
css = ''
attributes = ''
return result


Expand Down
13 changes: 6 additions & 7 deletions src/rimu/lists.py
@@ -1,9 +1,9 @@
import re
from typing import List, Match, Optional, Pattern

from rimu import (blockattributes, delimitedblocks, expansion, io, lineblocks,
options, utils)

from typing import Optional, Pattern, Match, List
from rimu.expansion import Expand
import re


class Def:
Expand Down Expand Up @@ -112,13 +112,12 @@ def renderListItem(item: ItemInfo, reader: io.Reader, writer: io.Writer) -> Opti
match = item.match
text: str
if d.termOpenTag: # => definition list.
writer.write(blockattributes.injectHtmlAttributes(d.termOpenTag))
writer.write(blockattributes.injectHtmlAttributes(d.termOpenTag, consume=False))
blockattributes.id=''
text = utils.replaceInline(match[1], Expand(macros=True, spans=True))
writer.write(text)
writer.write(d.termCloseTag)
writer.write(d.itemOpenTag)
else:
writer.write(blockattributes.injectHtmlAttributes(d.itemOpenTag))
writer.write(blockattributes.injectHtmlAttributes(d.itemOpenTag))
# Process item text from first line.
itemLines = io.Writer()
text = match[match.re.groups]
Expand Down
12 changes: 6 additions & 6 deletions tests/rimu-tests.json
Expand Up @@ -2468,7 +2468,7 @@
}
},
{
"unsupported": "go,kt,dart",
"unsupported": "go,kt,dart,py",
"description": "line block macro expression value definition",
"input": "{foo} = `(parseInt(40) + parseInt(2)) + 'px'`\n{foo}",
"expectedOutput": "<p>42px</p>",
Expand All @@ -2478,7 +2478,7 @@
}
},
{
"unsupported": "go,kt,dart",
"unsupported": "go,kt,dart,py",
"description": "multi-line macro expression value definition",
"input": "{foo} = `(parseInt(40) + parseInt(2)) \n+ 'px'`\n{foo}",
"expectedOutput": "<p>42px</p>",
Expand All @@ -2488,7 +2488,7 @@
}
},
{
"unsupported": "go,kt,dart",
"unsupported": "go,kt,dart,py",
"description": "delimited block macro expression line continuation",
"input": "{foo} = `(parseInt(40) + parseInt(2)) + ` \\\npx``\n{foo}",
"expectedOutput": "<p>42\npx</p>",
Expand All @@ -2498,7 +2498,7 @@
}
},
{
"unsupported": "go,kt,dart",
"unsupported": "go,kt,dart,py",
"description": "delimited block macro expression escaped line continuation",
"input": "{foo} = `(parseInt(40) + parseInt(2)) + ` \\\\\npx``\n{foo}",
"expectedOutput": "<p>42 px</p>",
Expand All @@ -2508,7 +2508,7 @@
}
},
{
"unsupported": "go,kt,dart",
"unsupported": "go,kt,dart,py",
"description": "illegal macro expression",
"input": "{foo} = `1 + x`",
"expectedOutput": "",
Expand Down Expand Up @@ -2601,7 +2601,7 @@
{
"description": "Block Attributes applied labelled list terms",
"input": ".#id1\nOne:: Item one.\n\n.#id2\n.class\nTwo:: Item two.",
"expectedOutput": "<dl id=\"id1\"><dt>One</dt><dd>Item one.</dd><dt class=\"class\" id=\"id2\">Two</dt><dd>Item two.</dd></dl>",
"expectedOutput": "<dl id=\"id1\"><dt>One</dt><dd>Item one.</dd><dt class=\"class\" id=\"id2\">Two</dt><dd class=\"class\">Item two.</dd></dl>",
"expectedCallback": "",
"options": {
"reset": true
Expand Down

0 comments on commit 503e98f

Please sign in to comment.