Commit graph

330 commits

Author SHA1 Message Date
Noah Hellman
d2a46663f1 html: fix initial newline when hr first element 2023-04-29 14:21:11 +02:00
Noah Hellman
99f4691e52 lib: emit footnotes as they are encountered
Previously, footnotes and their children events were skipped (stored in
block tree) and inline parsed at the end. Now, they are emitted by the
parser immediately and the responsibility to aggregate them has been
moved to the renderer.

resolves #31
2023-04-25 21:03:18 +02:00
Noah Hellman
c4ecd0c677 Revert "lib: add Render::render_{event, prologue, epilogue}"
This reverts commit e8503e28fd.

This imposed too many limitations on the renderer implementation. E.g.
making it impossible to store `Event<'s>`'s in the renderer struct.

Revert back to having the renderer struct separate from the implementor
of the Render trait. The implementor may instead create a renderer
struct without any restrictions.
2023-04-25 21:03:18 +02:00
Noah Hellman
8e48021f7a lib: emit LinkDefinition event
resolves #14
2023-04-25 21:03:18 +02:00
Noah Hellman
17b166867f html: derive Renderer::default
setting defaults manually mostly causes rebase conflicts
2023-04-25 21:03:18 +02:00
Noah Hellman
bdab4f021b lex: eat non special chars separately
let tight loop work as long as there no special characters
2023-04-25 20:26:47 +02:00
Noah Hellman
3701d282ac lex: separate escaped/non-escaped 2023-04-25 20:26:47 +02:00
Noah Hellman
e877fdbde8 inline: rm resolved TODO
resolved by a846477cea
2023-04-25 18:35:13 +02:00
Noah Hellman
ab33adc799 lib: cfg guard doctests using html renderer
docs do not compile when html feature is off otherwise
2023-04-25 18:35:10 +02:00
Noah Hellman
d2d7f5d474 lib: fix url in autolink/email end event
was constant ">" instead of actual url
2023-04-10 18:50:22 +02:00
Noah Hellman
1202160a88 inline: resume attr parsing when new lines received
instead of starting over for each new line
2023-04-05 21:17:33 +02:00
Noah Hellman
50205573d0 inline: store attributes in vec 2023-04-05 21:17:33 +02:00
Noah Hellman
62d33effc4 inline: parse multiline attributes
reimplement after broken by "take str per line instead of full inline
iter" commit

also resolves #18 and #34
2023-04-05 21:17:33 +02:00
Noah Hellman
3d42820001 inline: add ControlFlow enum
needed to indicate that more input is needed

this is needed only for multiline attributes that require backtracking
2023-04-05 21:17:33 +02:00
Noah Hellman
7133de94bb inline: keep track of lines ahead
Needed for attributes, as they cannot be parsed without backtracking.
Potentially we have to parse for attributes until the end of the block
before we can know if it is invalid attributes and we should instead
parse for other inline events.
2023-04-05 21:17:33 +02:00
Noah Hellman
2bcc6122ca inline: store link cowstrs in vec
try to reduce size of Event by placing the cowstr in a shared vec, and
just keeping an index in the event itself

seems to have a significant performance benefit on benchmarks
2023-04-05 21:17:33 +02:00
Noah Hellman
a846477cea inline: parse multi-line link tags/urls
reimplement after broken by "take str per line instead of full inline
iter" commit

this also resolves #22
2023-04-05 21:17:33 +02:00
Noah Hellman
98f3fe5c7c attr: Parser overhaul
- allow reading one line at a time, values may span multiple inputs
- mv event push to Parser, allowing reuse from outside Attributes::parse
- get rid of Element, simplify
2023-04-05 21:17:33 +02:00
Noah Hellman
34e74ddc43 attr: impl valid without Parser
only State fsm is needed

try to use Parser only when attributes need to be stored
2023-04-05 21:17:33 +02:00
Noah Hellman
242a64e3b4 attr: mv wildcard State use to Parser methods
avoid potential name conflict
2023-04-05 21:17:33 +02:00
Noah Hellman
172f555272 attr: step one char at a time
make sure attr can keep track of all state so one char can be provided
at a time

this allows not restarting from beginning if we find out we need more
chars to finish parsing attributes
2023-04-05 21:17:33 +02:00
Noah Hellman
e1b12ba642 attr: rename State::{Attribute->Key}
more accurate name
2023-04-05 21:17:33 +02:00
Noah Hellman
86ee4ee520 lex: rm lex::Kind::Whitespace
Whitespace tokens do not necessarily create new events but they work as
a delimiter for words with attributes and affect some container
delimiters. Now when we can read the source from inline, we can instead
inspect for whitespace when needed.

Removing the whitespace token allows the lexer to continue a lot longer
without stopping. E.g. a typical line in a paragraph with no special
characters can turn into a single token.
2023-04-05 21:17:33 +02:00
Noah Hellman
9454a2e393 inline: apply word attribute when flushing event buf
fixes issue with e.g `[text]({.cls})` where attributes get immediately
applied to `[text](` where link should have priority.
2023-04-05 21:17:33 +02:00
Noah Hellman
08ef15655b inline: extract merge_str_events
decrease size of inline::Parser::next, make more readable
2023-04-05 21:17:33 +02:00
Noah Hellman
1b7bb25519 inline: allow reading src 2023-04-05 21:17:33 +02:00
Noah Hellman
8382fe122f lib: derive Clone for Parser
should now be safe to do
2023-04-05 21:17:33 +02:00
Noah Hellman
3a1a3996e9 inline: take str per line instead of full inline iter
gets rid of DiscontinousChars which is large and requires cloning on
peek

resolves #4
2023-04-05 21:17:33 +02:00
Noah Hellman
8169feb1f6 inline: impl links w/o lookahead
needed to get rid of DiscontinuousChars
2023-04-05 21:17:33 +02:00
Noah Hellman
66d821f03e inline: replace Delim by Opener
no need to have a delimiter for closer, only opener needs to be stored
in stack
2023-04-05 21:17:33 +02:00
Noah Hellman
ed5aed3759 inline: impl verbatim w/o lookahead
avoid lookahead for containers that can cross newline

needed to get rid of DiscontinuousChars iter
2023-04-05 21:17:33 +02:00
Noah Hellman
e8e551fd8b inline: separate lex, span to separate Input object
easier handling of mutable pointers, can borrow self.input instead of
whole self

can e.g. borrow mutable state while still eating new tokens
2023-04-05 21:17:33 +02:00
Noah Hellman
5d6d0e0840 inline: use lex kinds
import Sequence and use Delimiter, Symbol consistently
2023-04-05 21:17:33 +02:00
Noah Hellman
f192ea2aa6 inline: use ? to flatten methods 2023-04-05 21:17:33 +02:00
Noah Hellman
491c5f2866 inline: always push events from parse methods
in order to more conveniently allow pushing in arbitrary order

parse methods now return an Option<()> that functions kind of like a
std::ops::ControlFlow. Some(()) means the token was parsed, None means
continue parsing.
2023-04-05 21:17:33 +02:00
Noah Hellman
9429f90307 inline: reuse event buffer between blocks
make sure not to allocate a new buffer on each block
2023-04-05 21:17:33 +02:00
Noah Hellman
1e5e56c463 only assert in debug builds
these are primarily used to detect bugs during e.g. fuzzing.

most of these asserts have negligible impact on performance, but if they
are not debug asserts it is not obvious that they dont affect
performance of release builds
2023-04-05 21:17:33 +02:00
Noah Hellman
d171cbb516 inline: add quote test 2023-04-05 21:17:33 +02:00
Noah Hellman
0a501fec10 lib: add test attr_inline_consecutive{,_invalid} 2023-04-05 21:17:33 +02:00
Noah Hellman
718f2df60e lib: add test link_reference_multiline 2023-04-05 21:17:33 +02:00
Noah Hellman
66fd099af1 lib: add test attr_inline_multiline 2023-04-05 21:17:33 +02:00
Noah Hellman
722f549ffd clippy: allow blocks_in_if_conditions everywhere 2023-04-05 21:17:33 +02:00
Noah Hellman
f31398a796 attr: impl Debug for Attributes manually
show key value pairs instead of internal structure
2023-04-05 21:17:33 +02:00
Noah Hellman
10788af246 lib: add Render::{push, write}_borrowed
allow rendering iterators with borrowed events

resolves #24
2023-04-05 21:17:33 +02:00
Noah Hellman
e8503e28fd lib: add Render::render_{event, prologue, epilogue}
derive push/write automatically from these
2023-04-05 21:17:33 +02:00
Noah Hellman
e506fffed8 mv push/write examples from html to Render trait
They apply more to the Render trait now than the implementation in the
html module
2023-04-05 21:17:33 +02:00
Noah Hellman
8eafdf073b html: extract Writer::render_{event, epilogue} 2023-04-05 21:17:33 +02:00
Noah Hellman
3d1b5f2115 html: rm events/out from Writer
separate input/output from rendering state
2023-04-05 21:17:33 +02:00
Noah Hellman
f5724fcc9c html: rm FilteredEvents
no longer useful as no peeking is needed, use simple early exit instead
2023-04-05 21:17:33 +02:00
Noah Hellman
336927faef html: avoid peek of next event
Try to make rendering of each event independent.

The only case where we need to peek is when a backref link should be
added to the last paragraph within a footnote.

Before, when exiting a paragraph, we would peek and add the link before
emitting the close tag if the next event is a the footnote end.

Now, the paragraph end event skips emitting a paragraph close tag if it
is within a footnote. The next event will then always close the
paragraph, and if it is a footnote end, it will add the backref link
before closing.
2023-04-05 21:17:33 +02:00