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

Upgrade to highlight.js v11 #734

Merged
merged 1 commit into from
Dec 25, 2022
Merged

Conversation

lread
Copy link
Member

@lread lread commented Dec 24, 2022

I was on the fence about this one as v11 removed auto-merging of HTML into formatted blocks. This feature supports AsciiDoc callouts. See: https://docs.asciidoctor.org/asciidoc/latest/verbatim/callouts/ if you need a reminder as to what these are.

After more carefully reading over highlightjs/highlight.js#2889, I realized maybe it wouldn't be very difficult to simply re-introduce the feature. The issue even includes a complete JavaScript code example to do so.

I did my naive best to transcribe the sample JavaScript to TypeScript (which even caught a couple of minor issues).

It took me some time to figure out a way to expose the TypeScript function to our layout page. Parcel.js used to provide a --global option to support this use case, but that feature was removed.

In the end I just assigned the function to the browser window to make it available.

There is a new console warning in highlight.js v11 that is generated when formatted code contains unescaped HTML. I turned this off because the adoc callouts add... you guessed it... unescaped HTML. We also have good HTML sanitization, so I think we are good here.

I was on the fence about this one as v11 removed auto-merging of HTML
into formatted blocks. This feature supports AsciiDoc callouts.
See: https://docs.asciidoctor.org/asciidoc/latest/verbatim/callouts/ if
you need a reminder as to what these are.

After more carefully reading over highlightjs/highlight.js#2889, I
realized maybe it wouldn't be very difficult to simply re-introduce the
feature. The issue even includes a complete JavaScript code example to
do so.

I did my naive best to transcribe the sample JavaScript to TypeScript
(which even caught a couple of minor issues).

It took me some time to figure out a way to expose the TypeScript
function to our layout page. Parcel.js used to provide a --global
option to support this use case, but that feature was removed.

In the end I just assigned the function to the browser window to make it
available.

There is a new console warning in highlight.js v11 that is generated
when formatted code contains unescaped HTML. I turned this off because
the adoc callouts add... you guessed it... unescaped HTML. We also have
good HTML sanitization, so I think we are good here.
@lread
Copy link
Member Author

lread commented Dec 24, 2022

@corasaurus-hex I wonder if I've committed any especially horrible TypeScript/JavaScript sins here. 🙂

I'll go ahead and merge soon, but I am happy to adapt based on any feedback you might have.

@lread lread merged commit 81408a4 into cljdoc:master Dec 25, 2022
@corasaurus-hex
Copy link
Contributor

That global state makes me itch but if it worked in the original plugin then it likely works here and I'm ok with it. Looks good!

@corasaurus-hex
Copy link
Contributor

And yes, assigning it to the global object (in the browser that's typically the window) is the right way to make something globally available elsewhere.

@lread
Copy link
Member Author

lread commented Dec 25, 2022

Thanks @corasaurus-hex, much appreciated!

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

2 participants