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

Drop default parsing of hashtags and internal links #14

Merged
merged 6 commits into from
Feb 13, 2023

Conversation

zampino
Copy link
Collaborator

@zampino zampino commented Feb 13, 2023

This changes the default behaviour of nextjournal.markdown/parse with respect to custom text tokenization: hashtags e.g #tag and internal links [[link] are not parsed by default any longer. Users can opt-in of them by:

(md/parse (update md.parser/empty-doc :text-tokenizers conj 
                  md.parser/internal-link-tokenizer 
                  md.parser/hashtag-tokenizer)
          "some [[set]] of [[wiki]] links with #hashtags")
;; => 
=>
{:type :doc,
 :content [{:type :paragraph,
            :content [{:type :text, :text "some "}
                      {:type :internal-link, :text "set"}
                      {:type :text, :text " of "}
                      {:type :internal-link, :text "wiki"}
                      {:type :text, :text " links with "}
                      {:type :hashtag, :text "hashtags"}]}],
 :toc {:type :toc},
 :footnotes []}

See also this notebook.

There has never been an actual agreement, what exactly hashtags and internal links should have linked to, when transformed into hiccup.

We allow to add a predicate to specify in which situation a tokenizer should be applied, see:

(def hashtag-tokenizer
{:regex #"(^|\B)#[\w-]+"
:pred #(every? (complement #{:link}) (map :type (current-ancestor-nodes %)))
:handler (fn [match] {:type :hashtag :text (subs (match 0) 1)})})

@zampino zampino marked this pull request as ready for review February 13, 2023 13:51
@zampino zampino merged commit 581f17d into main Feb 13, 2023
@zampino zampino deleted the rethink-custom-tokenization branch February 13, 2023 14:29
mk pushed a commit to nextjournal/clerk that referenced this pull request Feb 14, 2023
Since we never agreed on what either #tags or [[internal links]] should point to when rendered as html, we decided to stop parsing such expressions by default and rely on context-specific customization instead. We will restore suitable viewers once it's clear how tags and wiki-style links should behave.

Closes #383.

See nextjournal/markdown#14 for more context and examples.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant