-
-
Notifications
You must be signed in to change notification settings - Fork 98
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
Code syntax hightlighting #1484
Comments
I have a suggestion. I think that writing any syntax highlighting code is a waste of time (although I like wastes of time as much as anyone). I decided to figure out finally how to fool script -qc 'vimpager --force-passthrough ~/Workspace/glifparser.rlib/src/glif.rs' | dos2unix -f | aha > /tmp/aha.html Here's some output: (no <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- This file was created with the aha Ansi HTML Adapter. https://github.com/theZiz/aha -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="application/xml+xhtml; charset=UTF-8"/>
<title>stdin</title>
</head>
<body>
<pre>
<span style="color:#ffd7d7;">//! [`Glif`] (`<glif>` toplevel), read/write modules, + [`Lib`]</span>
<span style="color:olive;">use</span> <span style="color:#5fd7ff;">std</span><span style="color:#ffd7d7;">::</span>path;
<span style="color:olive;">use</span> <span style="color:#5fd7ff;">crate</span><span style="color:#ffd7d7;">::</span><span style="color:#5fd7ff;">anchor</span><span style="color:#ffd7d7;">::</span>Anchor;
<span style="color:olive;">use</span> <span style="color:#5fd7ff;">crate</span><span style="color:#ffd7d7;">::</span><span style="color:#5fd7ff;">component</span><span style="color:#ffd7d7;">::</span>GlifComponents;
<span style="color:olive;">use</span> <span style="color:#5fd7ff;">crate</span><span style="color:#ffd7d7;">::</span><span style="color:#5fd7ff;">error</span><span style="color:#ffd7d7;">::</span>GlifParserError;
<span style="color:olive;">use</span> <span style="color:#5fd7ff;">crate</span><span style="color:#ffd7d7;">::</span><span style="color:#5fd7ff;">guideline</span><span style="color:#ffd7d7;">::</span>Guideline;
<span style="color:#5fd7ff;">#[cfg(feature = </span><span style="color:purple;">"glifimage"</span><span style="color:#5fd7ff;">)]</span>
<span style="color:olive;">use</span> <span style="color:#5fd7ff;">crate</span><span style="color:#ffd7d7;">::</span><span style="color:#5fd7ff;">image</span><span style="color:#ffd7d7;">::</span>GlifImage;
<span style="color:olive;">use</span> <span style="color:#5fd7ff;">crate</span><span style="color:#ffd7d7;">::</span><span style="color:#5fd7ff;">point</span><span style="color:#ffd7d7;">::</span>PointData;
<span style="color:olive;">use</span> <span style="color:#5fd7ff;">crate</span><span style="color:#ffd7d7;">::</span><span style="color:#5fd7ff;">outline</span><span style="color:#ffd7d7;">::</span>{Outline, OutlineType};
<span style="color:olive;">mod</span> <span style="font-weight:bold;color:teal;">conv</span>;
<span style="color:olive;">mod</span> <span style="font-weight:bold;color:teal;">lib</span>;
<span style="color:olive;">pub</span> <span style="color:olive;">use</span> <span style="color:#5fd7ff;">lib</span><span style="color:#ffd7d7;">::</span>Lib;
<span style="color:olive;">mod</span> <span style="font-weight:bold;color:teal;">read</span>;
<span style="color:olive;">pub</span> <span style="color:olive;">use</span> <span style="color:#5fd7ff;">self</span><span style="color:#ffd7d7;">::</span><span style="color:#5fd7ff;">read</span><span style="color:#ffd7d7;">::</span>read_ufo_glif <span style="color:olive;">as</span> read;
… It's then a matter of just using SILE's XML mode, right? Significantly less complicated starting commands exist btw, such as pygmentize ~/Workspace/glifparser.rlib/src/glif.rs | aha -b > /tmp/aha.html But |
@ctrlcctrlv Good points. In the same vein (using external tools):
|
Good point about robustness. What about calling |
I am not sure I understand here. If SILE has to rely on a headless browser as 3rd party for such a simple thing... We could as well ditch SILE as a whole and use that headless browser for everything (with those W3C Paged Media things such as paged.js)... It's very delicate, at best, to let headless browsers enter the game ;) |
Well that's not really what I meant. Since all we need to 'compute' is whether an element is bold and its color, I more meant to figure out what libraries do that :) |
On the "minimal" approach (= Lua only, for our manual), I just noticed Penlight include a (basic) Lua lexer. Might be a good start point for supporting at least Lua syntax highlighting without any new dependency. |
How often are people using SILE to write about Lua outside our own documentation? One of my papers includes syntax highlighted Perl, and I would've liked to do it with SILE. Supporting it in Lua biases future work to also be in Lua. |
Maybe useful — https://github.com/rdlaitila/LURE |
Yes, you are on point, and that's why I opened this issue ;) - I mean, there are really two things here:
|
I agree with you there, I just had my best idea yet although you've already had it :)
For some reason I thought ANSI was so arcane that it'd be easier to handle it in HTML/CSS, not so. I think that working on Kitty terminal emulator has jaded me a little too much haha. But I looked at https://github.com/theZiz/aha/blob/5eaec96aae98274d1d86b431b9d426d50a023fbc/aha.c#L735 I think we should refocus the problem around ANSI instead of HTML/CSS. I don't think it'd be hard to write an LPEG parser for ANSI now that I think about it. ¹ There's nothing wrong with Kitty, it just supports so many terminal standards that the problem seemed more daunting than it actually is. There's no reason we should need to support Sixels, images, Kitty's fancy box drawing with sprites, etc. |
This code seems to get us very close. It'd then be up to users how they make the files, be it with |
@ctrlcctrlv Will I have to make the ANSI coloured files in advance, or could I use a normal markdown file and tell sile that to turn a ``` section into ANSI it needs to call |
I haven't dug into this issue, but a few comments:
@rjmunro That question wasn't for me but given the current architecture it should never be required to prepare some special format in advance, a SILE package can call out to whatever tooling is required to transform input into whatever format it needs. I think the discussion here is just about what tooling to call out to. |
Thanks for the fruitful discussion. When I opened that issue in July 2021, I hadn't used yet the new luarocks-based packaging system. I wholly agree with @alerque 's last comment that such features are, likely, best addressed by 3rd-party packages (that then have the choice of using the implementation and/or external tools they want, without adding more dependencies to SILE's core distribution itself). I added to #1194 one small idea mentioned here (using Penlight's Lua lexer for e.g. autodoc to have a naive Lua syntax-hightlighter for in-documentation snippets of Lua code). Other than that, I consider my issue/question as wholly answered. |
As part of the efforts on native Markdown overhaul #1481, to ensure all features are discussed and addressed, I'd like to raise the question of code/syntax highlighting.
We could possibly have two use cases for supporting nice syntax highlighting for snippets of code:
~~~lua ...
(with backticks too, but that's annoying to escape here 🤣 )Some possible options (non-exhaustive):
What could be our take on this topic and are other end-users interested too?
The text was updated successfully, but these errors were encountered: