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

factor out inline writes for write_md #87

Closed
yshavit opened this issue Jun 30, 2024 · 1 comment · Fixed by #96
Closed

factor out inline writes for write_md #87

yshavit opened this issue Jun 30, 2024 · 1 comment · Fixed by #96

Comments

@yshavit
Copy link
Owner

yshavit commented Jun 30, 2024

write_md carries a bunch of state, including heap-allocated state, which it needs for handling references.

In link_transform::inlines_to_string (introduced in #86), we have a &Vec<Inline> that we need to write as markdown, but it cannot contain links (per the GFM spec) and thus doesn't need all that state. 1

We could be more efficient by factoring the inlines-writing to an InlineMdWriter<L: LinkWriter>, where LinkWriter is a new trait. In the general write_md case, that trait would hold all the ref-handling state that MdWriterState holds today, but in the link_transform::inlines_to_string, we would just ignore link definitions altogether (since we don't expect to see links).

Footnotes

  1. I'm pretty sure it can't contain footnotes, either. If you try, the footnote does appear (which it doesn't if you have the [^a]: blah definition but no reference to it), but the link breaks and does not contain a reference down to that footnote). Anyway, it's a weird case.

@yshavit
Copy link
Owner Author

yshavit commented Jun 30, 2024

Example of a link that contains a footnote:

[hello [^a] world][1]

[1]: https://example.com
[^a]: the footnote text

hello 1 world

(note: the footnote itself will be all the way down at the bottom)


Note:

  • the hello [^a] world text shows up just as hello [^a], with world not part of the link
  • the footnote shows up as [1], not [1] as expected
  • clicking on the link or the footnote definition does work

This suggests that an inline writer would still need to keep track of the footnotes, or at least append them to a &mut that eventually pipes to something equivalent to today's MdWriterState::seen_footnotes.

Footnotes

  1. the footnote text

yshavit added a commit that referenced this issue Jun 30, 2024
I think I want to do #87 first, not for performance but for better
organizing: I need a place to store the refs as I stream them out.
@yshavit yshavit closed this as completed in 15bab5b Jul 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant