[highlightjs] Add new addon #737
No reviewers
Labels
No labels
2018.09
2019.01
2019.03
2019.06
2019.09
2019.12
2020.03
2020.06
2020.09
2020.12
2021.03
2021.07
2021.09
2022.02
2022.06
2022.09
2022.12
2023.04
2023.05
2023.09
2024.03
2024.06
2024.09
2024.12
dependencies
Hackathon 2021
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: friendica/friendica-addons#737
Loading…
Reference in a new issue
No description provided.
Delete branch "task/add-new-highlightjs-addon"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Related to https://github.com/friendica/friendica/pull/5765
Since we aren't doing syntax highlighting in the core, I'd figured people would like a replacement, and this is the one.
Depends on https://github.com/friendica/friendica/pull/5773
We are so late in the release that I really have problems in merging some huge PR like this and the corresponding one in the core. We surely would need several days of testing - but I would prefer having the release this week.
This can actually wait, the other can't. No post with highlighted code was coming through at all.
The only interesting file in this addon is
highlightjs.php
, the rest is the JS library itself.Does it work with new content added by ajax (next page / new posts) ?
That's an excellent question, I haven't been able to see this in the wild yet, but I don't believe it would.
Issue confirmed, no syntax highlighting on ajax (re)load.
For new posts:
I would say we would need a new js hook in
main.js
before we update the scroll position. Maybe at the end ofupdateConvItems()
. When the hook is called the addon would need to execute something like(https://github.com/highlightjs/highlight.js/issues/966#issuecomment-152122946)
or
(https://github.com/highlightjs/highlight.js/issues/909#issuecomment-131686186)
Same for
loadScrollContent();
or we use another javascript code highlighter
maybe Prism (http://prismjs.com). We would execute
Prism.highlightAll();
at the end ofupdateConvItems()
(https://schier.co/blog/2013/01/07/how-to-re-run-prismjs-on-ajax-content.html) or if we want to have an eye on performance we could usePrism.highlightAllUnder(element, async, callback)
for the new content (https://prismjs.com/extending.html).Thank you for looking into it, my plan was to add an custom event on the
<body>
tag triggered by the Ajax load and then add an event listener in the<script>
tag added by the addon. This is the most unobtrusive way of handling this, and it may be used for other addons as well without having to tamper with the main JS routine.Phew!
I managed to make syntax highlighting work with Ajax, but not without completely reworking the Javascript hooks and rewriting the MathJax addon in the process 🤔
I added ways to register stylesheets and javascript files so that no HTML is written by hand in the hooks.
I had to create two new hooks and remove a completely useless part of
App->page
, but it's ready now.This is ready to merge now.