Skip to content

Commit

Permalink
Allow multiple node return (#2713)
Browse files Browse the repository at this point in the history
* Pack ParseConfig into Stream. Allow multiple nodes to be returned at once. Break WholeElement into multiple ParseNodes.

* Whoops, don't override the existing node whenever there's text.

* Make Result a generic type so I actually know what I'm returning in each spot.

* Keep escaping markdown code spans

* Properly clear the last node when I stop seeing nodes.

* Move curlifying over to a final step I do on text nodes.

* Handle *all* the places where Text gets generated, and move curlify to a Text method.

* Argh, still need to check for a word character after the apos.

* Cache the length of the stream

* Allow for nodes to *decrement* the line count as well, if they print to more lines than they occupied in the source.

* Update tests

* lint
  • Loading branch information
tabatkins authored Nov 15, 2023
1 parent dba9c3d commit 212ecfa
Show file tree
Hide file tree
Showing 8 changed files with 287 additions and 190 deletions.
20 changes: 14 additions & 6 deletions bikeshed/InputSource.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,27 @@ def lines(self) -> list[line.Line]:
offset = 0
for i, text in enumerate(self.rawLines, 1):
lineNo = i + offset
# The early HTML parser runs before Markdown,
# and in some cases removes linebreaks that were present
# in the source. When properly invoked, it inserts
# a special PUA char for each of these omitted linebreaks,
# so I can remove them here and properly increment the
# line number.
# The early HTML parser can change how nodes print,
# so they occupy a different number of lines than they
# had in the source. Markdown parser needs to know
# the correct source lines, tho, so when this happens,
# the nodes will insert special PUA chars to indicate that.
# I can remove them here and properly adjust the line number.
# Current known causes of this:
# * line-ending -- turned into em dashes
# * multi-line start tags
# * multi-line markdown code spans;
# - the text loses its newlines
# - the original text goes into an attribute on the start
# tag now
ilcc = constants.incrementLineCountChar
dlcc = constants.decrementLineCountChar
if ilcc in text:
offset += text.count(ilcc)
text = text.replace(ilcc, "")
if dlcc in text:
offset -= text.count(dlcc)
text = text.replace(dlcc, "")

ret.append(line.Line(lineNo, text))

Expand Down
1 change: 1 addition & 0 deletions bikeshed/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
macroStartChar = "\uebbb"
macroEndChar = "\uebbc"
incrementLineCountChar = "\uebbd"
decrementLineCountChar = "\uebbf"
bsComment = "<!--\uebbe-->"
Loading

0 comments on commit 212ecfa

Please sign in to comment.