Font with Built-In Syntax Highlighting
blog.glyphdrawing.club
blog.glyphdrawing.club
One small note: the post seems slightly confused about the use of OpenType features, as it calls for:
font-feature-settings: "colr", "calt";
but there's no 'colr' feature tag in the font's OpenType layout tables, so that's meaningless here.I suppose this was intended to "activate" the color glyph table (COLR) in the font; but that isn't an OpenType layout feature that would be controlled by font-feature-settings, and doesn't need to be "turned on" like this.
(In addition, the 'calt' feature is (according to the spec[1]) supposed to be active by default, so it shouldn't be necessary to explicitly set it either. And indeed, the font works for me in both Firefox and Chrome without this rule; sadly Safari doesn't seem to handle it.)
[1] https://learn.microsoft.com/en-gb/typography/opentype/spec/f...
Putting animated SVG in a font [1] is a horrible hack; this one is benign.
A somehow larger stretch would be a font with a built-in spell checker, with a wavy underline under every letter that only disappears under correctly spelled words.
Agreed, that is even more horrible. And probably just for performance reason alone should never ever get close to a real world product. Still, quite neat.
sub Quote @Char' by @CharQuoted;
sub Backslash.quoted Backslash' by Backslash.quoted2;
sub Backslash.quoted Quote' by Quote.escaped;
sub [@NonQuoteQuoted Quote.escaped Backslash.quoted2] @Char' by @CharQuoted;
I don't know if context can be carried between different lines. @Char = [a-z quotedbl backslash];
@CharQuoted = [A-Z quotesingle slash];
@NonQuoteQuoted = [A-Z slash];
@Escaped = [asterisk dollar];
feature liga {
lookup xa {
sub quotedbl @Char' by @CharQuoted;
sub slash backslash' by dollar;
sub slash quotedbl' by asterisk;
sub [@NonQuoteQuoted asterisk dollar] @Char' by @CharQuoted;
} xa;
} liga;
feature liga {
lookup xb {
sub quotesingle' by quotedbl;
sub slash' by backslash;
sub dollar' by backslash;
sub asterisk' by quotedbl;
} xb;
} liga; s n a' k e -> ā
s n ā k e' -> NULL
although that would also change "snāke" to "snāk", which is not quite what you asked for.I don't think there's a way to do many-to-many substitution in general, although it would always be possible if you create intermediate glyphs. I believe Section 5 of http://adobe-type-tools.github.io/afdko/OpenTypeFeatureFileS... gives the full list of substitution types.
Impossible before. It can't be less invasive: _original text stays intact_ - no wrapping tags.. no JS.. just works with userContent.css.. - simply another dimension.
> I'm also not an OpenType expert, so I'm sure the substitution logics could be improved upon. I'm open to sharing the modified source file to anyone interested. If you have any ideas, suggestions or feedback, let me know. You can reach me at hlotvonen@gmail.com.
- so, how far can it be improved then ?!
- what other font editors moreover to Glyph (mac only) have good support for advanced contextual alternates ?
And.. Introduction to OpenType Programming https://simoncozens.github.io/fonts-and-layout/features.html - about lookups.
For font editors, Glyphs is the industry standard, and, as far as I know, there are not many good alternatives. There's FontForge, but its contextual alternate editing seems even more confusing: https://fontforge.org/docs/ui/dialogs/contextchain.html
Just today I found out about a new browser based font editor, fontra, but it looks like editing OpenType features is still on its roadmap. Maybe something to keep an eye on though. https://fontra.xyz/
You asked what it takes to make a blog.
I have a html front page, tag pages and posts. All static.
There is a pretty short php page that takes an existing post or the dummy, chops off everything in front and behind the text.
The tag cloud sits under it. Clicking a tag injects it under the text.
When saved the top and bottom html are reatached and the title <h2> is copied into the <title> tag.
It then creates or overwrites the static html document.
It finds tags in the html and inserts a link to the new article into the tag and index pages.
Load, split, join and save is actually less complicated than sql and faster:)
Deleting tags and blogpostings is done manually.
Besides editpost.php there is a bookmarklet to inject quotes with links and youtube embeds.
1. I need to have two different versions of my site, dev and prod, which I find very restricting and fragile.
2. I don't like to rely on other people updating their npm packages just so I could publish static content. I've been burned too many times by abandoned npm packages or breaking changes.
So you can edit your HTML push and have a simple script to clean it before publishing it.
You can copy my blog is very simple and is generated with PHP
Perhaps especially if the sibling comment about embedding a state machine pans out?
any font editor that supports writing opentype feature code manually. glyphs for mac won’t really help you here: while glyphs will do its best to autogenerate as much opentype for you as it can, it doesn’t do much (anything?) for calt features
Really fun to see a font that can do this though. Never would've expected it.
To get an idea, I repeatedly duplicated the CSS in the "tiny sandbox" until there were nearly 20,000 lines there, and then profiled the operation of changing the font-size by 1px in Firefox. Reflowing the textbox took about 1.6 seconds.
With `font-feature-settings: "calt" off` applied, so that the contextual lookups aren't being run, a font-size change for that same textbox content reflows in about 100 milliseconds.
(I don't have actual timings for the same example in Chrome, but subjectively, with "calt" disabled, the resize is near-instant, whereas with it enabled, it's quite laggy, similar to Firefox.)
-= the highlight is always there, instantly =- (or.. it doesn't a look like a reason for jumpy lines because of redo) - definintly less cycles and memory overhead and I don't see that possible with DOM and JS - the delays could be there only because of inefficient editing operations with no impact of coloring.. and maybe with.. smaller textfragments (or ?) there could be no such delays at all - but simple* coloring coud be always so instant (and easy) ? (yes, I know, so far it may be also limiting and exclusive)
Edit: Perhaps this is a reminder that custom fonts are a potential attack vector for security-sensitive websites since font rendering runs highly-complex programs, probably in a language that isn't memory safe.
As you have guessed, this used a rendering feature that was not pure.
> This site doesn't use cookies or link to any third party site.
I love this. Thank you!There are many third party links that you can click on, which does align with the original ethos of the web.
> This site doesn't use cookies or <link> to any third party site.
:)
@font-face {
font-family: 'foo';
src: url(data:application/x-font-woff;charset=utf-8;base64,d09GRgABAAAAAGy …)
}(E.g. see https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_...)
This is one of the cooler things I've seen in a while!
<div>
</div>
at the end of the example, some of the letters of "div" would be green and some would be white.[1] Adding a class or something changed which letters were green and which white.*every* monospace text in the browser *syntax colored * :)
(as expected.. wherever it does make sense or not.. - viewsource, text files, parts of pages.. :)
Software Color Font Support (2022):
COLR SVG
- Yes Adobe Illustrator CC 2018
- Yes Adobe InDesign CC 2019
- Yes Adobe Photoshop CC 2018
Yes Yes Adobe QuarkXPress CC 2018
- Yes Sketch
- - Affinity Designer
Yes - Word
Yes Yes paint.net 4.0 (2014)
Yes - Corel Graphics Suite 2021
- - Figma
Yes Firefox, Safari
Yes all web browsers almost
( https://www.high-logic.com/font-editor/fontcreator/tutorials... )Could anybody make an online tool to choose another monospace font, programming language and color theme, and generate a syntax-highlighted font?
That said, we can have Notepad with built-in syntax highlighting now! https://fosstodon.org/@niutech/113028194839365739
XeLaTeX or LuaLaTeX should be able to do that, though I'm not sure offhand whether they successfully embed color fonts into the output PDF.
It would be so cool if you could override the contextual language (likely determined by file extension or explicitly in markdown or whatever) with a different one just by applying a font.
E.g. if you have a comment that starts with "/*" and ends several lines later with "*/", but the editor decides to just redraw a line in the middle, the highlighter won't "know" to use the comment color as the text-drawing operation won't include the delimiters.
(This issue already exists in a small way, as mentioned in https://news.ycombinator.com/item?id=41251114, but it'd only get worse as the syntax highlighter becomes more sophisticated.)
Ironically, it is Microsoft which developed CPAL/COLR (at least intially), and this is the least atrocious format across colored suggestions. The other options are SVG-in-OpenType (Adobe/Mozilla; https://helpx.adobe.com/fonts/using/ot-svg-color-fonts.html), PNG-in-OpenType/SBIX (Apple; https://developer.apple.com/fonts/TrueType-Reference-Manual/...), and CustomBitmap-in-OpenType/CBDT (Google; https://fonts.google.com/noto/use).
All of them are now OpenType standards, for better or worse.
Or did I misunderstand your comment? Care to elaborate on your idea?
It doesn't check that there's a closing quote, but it should work for highlighting syntactically valid code (once you fix my mistakes). I don't see a way for a character to affect others arbitrarily far back unless some fancier features like ignoring certain classes can be abused.
A reverse chain might work?
>For example, words within <p> tags that are JS keywords will be always highlighted
Especially because some keywords are usual words like in or with.
But still great idea nevertheless.
Can be used when syntax highlighting is not available.
[0]: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_fonts/V...
@font-palette-values --mycolors {
font-family: Monaspace;
base-palette: 0;
override-colors: 0 red, 1 green, 2 blue,
3 magenta, 4 cyan, 5 yellow;
}
(I just picked some arbitrary colors as a proof-of-concept; they don't actually look good.) Then adding the property: font-palette: --mycolors;
to the textarea element causes it to use these colors instead of the defaults in the font.This is the most interesting post in a long time, bravo!
<pre contenteditable="plaintext-only" class=""><code>...
I would love to see separate fonts for HTML, CSS, and JS only, as I would want to use it for lightweight HTML highlighting in textareas in a CMS.
does anyone know the original target of this OpenType feature? Struggling to imagine where it would fit apart from code highlighting
For instance handwriting fonts
I heard about security issues related to fonts and wondered “how in the world”. This helps clarify why.
It simply should not be possible.
As something practical, the author started with the wrong tool for the job (JavaScript), and then used an even more wrong tool for the same job (The font itself!)
Just use a code editor with Syntax Highlighting! Vim solved this decades ago!
Very interesting read, but don't try this at home.
Edit: Pandora's box is opened, I can see Jira and GitHub rushing to add support for this on their websites starting tomorrow =)
- and then with hardware accelerated font rendering https://news.ycombinator.com/item?id=41251199 ??
( ! ! ! )
I read such code every day in github and similar tools.
You are aware that this blog post is about displaying syntax highlighted code on the web? This is literally explained in the first paragraphs of the blog post..
As of now there were four ways of doing that:
1. using an image (which sucks)
2. manually setting the colors (good luck)
3. Generating the syntax highlighting server-side (preferred, but you need a backend that can do it)
4. Generating it client side using JS (waste of energy, takes a time to finish)
And now a font. Depending on the use case this could be a feasible option, although I am just waiting for this to be exploited in some fashion.
I still think computing once styling later is preferable.
Keyboard shortcuts and auto-complete being important pain points.
The author would like to hand code HTML for such web pages that would present syntax highlighted code to the web page reader, without requiring or resorting to typical js highlighting or screenshots.
None of editing in the terminal, nor an IDE, nor a browser are related to this use case.
https://frontendmasters.com/blog/syntax-highlighting-with-no...