-
-
Notifications
You must be signed in to change notification settings - Fork 296
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
Add code highlighting #31
Conversation
This is a first stab at having a configurable code highlighting option, similar to the MathJax rendering option. This change makes a checkbox in the settings for code highlighting using the highlightjs.org library. What works: code highlighting in multi-user env is like I would expect. single and anon(?) needs work Things to resolve/consider: - does the .IsCode test for code highlighting need to stay? At least this and that should use the same version of the highlight.js lib. - can the common templating part be 'included' somehow? - the anon vs single-user vs multi-user code is not completely clear (to me) - bring js to local instead of cloudfare cdn (perhaps combine with MathJax)
Thanks for contributing! To answer your questions:
That
You could include the common parts in a similar way to how the
You're right, single-user functionality (especially around posts) is quite finished. But see below for possible solution.
We can tackle this in a future pull request if you want. From a product standpoint, this is a great addition. But I think it should be more of a behind-the-scenes feature and doesn't need to be an explicit user option (the fewer, the better). MathJax is an explicit option because it potentially messes with the default Markdown rendering. I don't think that's necessary here because most people will probably want syntax highlighting in code blocks, especially if they explicitly choose a language by doing something like: ```python So I'd suggest that instead of making it a server-side setting, syntax highlighting should simply work when people add code to their posts. To do this, the JS should check for the existence of code blocks (as you're doing with the This keeps pages as light as possible / free of unnecessary JS in the absence of code blocks, while still supporting syntax highlighting. It also reduces friction by keeping the number of options for users as low as possible. |
|
But yeah, we can always do that later.
|
* master: Don't automatically include "v" from git Get versioninfo from the git repository
It now loads unconditionally and highlights all code blocks. TODO: optimize to not load when there are no blocks
Might as well do this right away, we're here anyway.
We load it always, no need for a user config UI
Couple of remarks:
|
Crux was the load event for the script tag inserted.
This could now be merged from my pov. |
* upstream/master: Work as a standalone server, including TLS Include About/Privacy page content in page description Show instance stats on About page Change default database name to writefreely Use and validate database type before connecting Mention Contributing Guide in README Add AUTHORS.md Fix About page link in Admin dash Include version in archives made by `make release` Remove keys.sh from make release Add make release
Nice! Great work here. To answer the remaining questions:
I'll review / test everything out a little later today or tomorrow. |
templates.go
Outdated
filepath.Join(templatesDir, "base.tmpl"), | ||
)) | ||
} else { | ||
templates[name] = template.Must(template.New("").Funcs(funcMap).ParseFiles( | ||
filepath.Join(templatesDir, name+".tmpl"), | ||
filepath.Join(templatesDir, "include", "footer.tmpl"), | ||
filepath.Join(templatesDir, "include", "render.tmpl"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want this included in every templated page, but we do need it if name == "collection" || name == "collection-tags" || name == "collection-post" || name == "post"
I think the best way to do this will be passing a []string
to a single ParseFiles()
call, where that array is constructed based on which template is being initialized. I'll make this change when I review this a little later.
Avoids loading render.tmpl where it isn't needed.
Okay, made those changes, and everything looks good! Would love to get support for more languages, but we can always do that later. Merging now. |
Cool, thanks. Having more languages is indeed something I would like to have too. Perhaps after the move to local js change? |
Yep, that'll work. Was thinking we could dynamically load in libraries for individual languages too, since there are so many available. |
This is a first stab at having a configurable code highlighting option,
similar to the MathJax rendering option. This change makes a checkbox
in the settings for code highlighting using the highlightjs.org
library.
What works: code highlighting in multi-user env is like I would
expect. single and anon(?) needs work
Things to resolve/consider:
this and that should use the same version of the highlight.js lib.
clear (to me)
MathJax)