Commit graph

355 commits

Author SHA1 Message Date
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
Noah Hellman
a603ea2124 lib: Add SpanLinkTag::Unresolved variant
keep the tag for unresolved links, and allow distinguishing between
`[tag][tag with empty url]` and `[tag][non-existent tag]`.

closes #26
2023-04-05 21:17:32 +02:00
Noah Hellman
05a4992d99 lib: don't prepend mailto to url in autolink Event
better to provide the original url, the event is already tagged as email

also avoids a string allocation
2023-04-05 21:17:04 +02:00
Noah Hellman
62e73100a6 bug fix: set LinkType to Email for email autolinks 2023-03-20 23:39:51 +01:00
Noah Hellman
14065177ae attr: fix name/key/value validation
match reference implementation
2023-03-17 18:57:36 +01:00
Noah Hellman
0719b2de65 block: fix class attribute parsing
match reference implementation
2023-03-17 18:57:36 +01:00
Noah Hellman
33d8215a2a html: fix invalid html for footnote inside image 2023-03-17 18:57:36 +01:00
Noah Hellman
c6022004bb html: fix alt text on nested images 2023-03-17 18:57:35 +01:00
Noah Hellman
fc374be56c html: escape img src values 2023-03-17 18:57:10 +01:00
Noah Hellman
5768b24907 html: escape quotes in img alt text 2023-03-17 18:45:20 +01:00
Noah Hellman
648a6dbef2 lib: derive Clone for Event and Container 2023-03-16 20:05:20 +01:00
kmaasrud
e3f39d4b88
feat: support escapes in attributes
Related issue: #1
2023-03-12 08:19:56 +01:00
Noah Hellman
a7f5b337a8 inline: fix attrs missing for inline verbatim
closes #15
2023-03-11 22:16:56 +01:00
Noah Hellman
418bb38f82 inline: extract ahead_container_attributes 2023-02-21 17:58:05 +01:00
Noah Hellman
c3ff064c78 make Event::is_{,container_}block public
this is only used by html renderer, may be useful for other renderers
also
2023-02-12 00:59:18 +01:00
Noah Hellman
413fecfe6a fix/allow clippy lints 2023-02-12 00:59:18 +01:00
kmaasrud
d7f2c0a819 implement Render trait for html::Renderer 2023-02-10 09:46:18 +01:00
kmaasrud
4743781cb9 add Render trait 2023-02-10 09:45:43 +01:00
kmaasrud
896c7004c4 add input and output args to CLI
This commit also adds a help text, accessible with the `--help` flag, as
well as a version text, available by using `--version`. My hope is that
this commit will make the jotdown CLI a bit friendlier to use.
2023-02-08 22:43:07 +01:00
Noah Hellman
b572790ac9 bug: fix tightness, ignore end blanklines 2023-02-07 21:51:31 +01:00
Noah Hellman
0d560901eb block: add Element::list 2023-02-07 21:49:35 +01:00
Noah Hellman
f98ebd477f bug: fix indent of footnote/list inner
when starting multiple blocks on same line, e.g. inner part of

    - - a
      - b

was

     - a
      - b

instead of

     - a
     - b
2023-02-06 23:09:48 +01:00
Noah Hellman
42360d7001 fixup! block: add MeteredBlock as intermediate struct 2023-02-06 23:09:48 +01:00
Noah Hellman
34452a282a features: add flag for html module 2023-02-05 21:59:38 +01:00
Noah Hellman
0de7776020 impl Clone, Copy on public objects 2023-02-05 20:36:49 +01:00
Noah Hellman
477eadde1c document lib API 2023-02-05 20:36:49 +01:00
Noah Hellman
5efb700c9b move atomic events to Event from Atom
An additional Atom enum seems to be more cumbersome and add little
value.

methods could potentially be used to classify events in several ways,
e.g.  block vs inline, atomic vs container
2023-02-05 20:36:49 +01:00
Noah Hellman
2811493c34 html: do not emit newline in beginning 2023-02-05 20:36:49 +01:00
Noah Hellman
7a26476315 fixup! wip djot -> html 2023-02-05 20:36:49 +01:00
Noah Hellman
0420aad0a5 implement symbols
e.g. :some-sym:
2023-02-05 20:36:49 +01:00
Noah Hellman
61f0d6281e rm unused 2023-02-05 20:36:49 +01:00
Noah Hellman
cc5a196149 fixup! parse block elements 2023-02-05 20:36:49 +01:00
Noah Hellman
cc89a06964 fixup! fixup! test_parse, test_block 2023-02-05 20:36:49 +01:00
Noah Hellman
fbd8811c86 block: parse description list 2023-02-05 20:36:49 +01:00
Noah Hellman
95bf52a31e update tree 2023-02-05 20:36:49 +01:00
Noah Hellman
768699d138 optionally use btree maps instead of hash maps
btree maps are deterministic which is useful for fuzzing. hash maps,
however have better performance in our case
2023-02-05 20:36:49 +01:00
Noah Hellman
924d6c44ac inline: disallow '<' in autolinks
avoid hangs on long <<<<<< sequences
2023-02-05 20:36:49 +01:00
Noah Hellman
82adc631d9 allow attributes on thematic breaks 2023-02-05 20:36:49 +01:00
Noah Hellman
670763dd93 fixup! do not treat \0 as EOF 2023-02-05 20:36:49 +01:00
Noah Hellman
59450ed9ad fixup! block: split parse_block function 2023-02-05 20:36:49 +01:00
Noah Hellman
cadf49fc53 fix usage of byte vs char count 2023-02-05 20:36:49 +01:00
Noah Hellman
4cb9c07cfc fixup! block attributes 2023-02-05 20:36:49 +01:00
Noah Hellman
82e1fd74f5 fixup! block: add MeteredBlock as intermediate struct 2023-02-05 20:36:49 +01:00
Noah Hellman
59be7070de block: count indent in chars instead of bytes 2023-02-05 20:36:49 +01:00
Noah Hellman
ca7f3c7e89 do not treat \0 as EOF
may appear in input
2023-02-05 20:36:49 +01:00
Noah Hellman
3425ad4189 fixup! block: avoid panic on too short table line 2023-02-05 20:36:49 +01:00
Noah Hellman
d2df3eb8a1 fixup! mv spans to separate span file 2023-02-05 20:36:49 +01:00
Noah Hellman
1bbfd4a96a prepass: avoid consecutive '-' in heading id 2023-02-05 20:36:49 +01:00
Noah Hellman
fb6a44283d inline: do not emit empty events 2023-02-05 20:36:49 +01:00
Noah Hellman
a5d88b64ae parser: avoid panic 2023-02-05 20:36:49 +01:00
Noah Hellman
c4a3acaf70 block: avoid panic on too short table line 2023-02-05 20:36:49 +01:00
Noah Hellman
87d4f7c270 prepass: use hash set to avoid duplicate heading ids
linear lookup becomes problematic for large amount of headings with same
title
2023-02-05 20:36:40 +01:00
Noah Hellman
6a94e694f9 block: enforce valid div classes 2023-02-05 20:36:40 +01:00
Noah Hellman
30351500bb fixup! attr valid: return whether attrs non-empty 2023-02-05 20:36:40 +01:00
Noah Hellman
dc38076f50 block: limit ordered list number width
use 64-bit to not let limit be too low, 32-bit allows for only 6 alpha
digits, "zzzzzz".
2023-02-05 20:36:40 +01:00
Noah Hellman
4b52fb0832 fixup! inline fixup 2023-02-05 20:36:40 +01:00
Noah Hellman
8dd4db11ec html: escape user provided attribute values 2023-02-05 20:36:40 +01:00
Noah Hellman
f9655dfa9b fixup! block: fix parsing end of list 2023-02-05 20:36:40 +01:00
Noah Hellman
5d9f90342c block: fix parsing end of list
following paragraphs were considered part of list
2023-02-05 20:36:40 +01:00
Noah Hellman
5672ef4198 block: fix empty lines in code block
were accidentaly removed
2023-02-05 20:36:40 +01:00
Noah Hellman
de7404137e parser: keep inlines of code blocks verbatim 2023-02-05 20:36:40 +01:00
Noah Hellman
2893977dae fixup! block: fix headings with first line empty 2023-02-05 20:36:40 +01:00
Noah Hellman
9ab8be5d30 block: move Block::from to Kind::block
allow more inputs
2023-02-05 20:36:40 +01:00
Noah Hellman
60dcf09c1a impl automatic heading identifiers 2023-02-05 20:36:40 +01:00
Noah Hellman
b726580724 parser: fix end section eating block attributes 2023-02-05 20:36:40 +01:00
Noah Hellman
7b8157cb51 fixup! parse inline attrs 2023-02-05 20:36:40 +01:00
Noah Hellman
3e8b80059e fixup! parser: impl link references 2023-02-05 20:36:40 +01:00
Noah Hellman
493a9b3563 heading event: limit level to u16 2023-02-05 20:36:40 +01:00
Noah Hellman
1135cf7054 fixup! block: parse tables 2023-02-05 20:36:40 +01:00
Noah Hellman
df8846cdba block: fix headings with first line empty 2023-02-05 20:36:40 +01:00
Noah Hellman
bfa58dfc0d block: allow repeating '#' in headings 2023-02-05 20:36:40 +01:00
Noah Hellman
451b2360f4 fixup! parser: apply link def attrs to link 2023-02-05 20:36:40 +01:00
Noah Hellman
dcb3b787a2 block: add MeteredBlock as intermediate struct 2023-02-05 20:36:40 +01:00
Noah Hellman
1c77b035b2 fixup! fixup! 27d710969473894b59f23ad981fc50cbd3b78977 2023-02-05 20:36:40 +01:00
Noah Hellman
25864fa467 fixup! block: add hierarchical heading sections 2023-02-05 20:36:40 +01:00
Noah Hellman
530820a04e block: add hierarchical heading sections 2023-02-05 20:36:40 +01:00