jgm / djot

A light markup language
https://djot.net
MIT License
1.63k stars 43 forks source link

Customizable Inlines #164

Open kalhauge opened 1 year ago

kalhauge commented 1 year ago

Fantastic project! Here is a possible feature that would make it a game changer for me.

I would like to see support for inline references like citations @cite and @sec:introduction; that way it would be easier to use in academic writing. But potentially is the problem much broader: every back end needs different syntax for different things. A Keyword in a book could be {! Hydrostatic !}, a citation could be @Knuth1968, a reference to another section could be !!introduction, math is $`x^2`, changes could be {- remove this -}, a tag references in knowledge bases are #my-interesting-topic, and hidden solutions to an exercise could be {!? the answer is 42 ?!}.

For example, there are different things wanted by people: https://github.com/jgm/djot/issues/10 https://github.com/jgm/djot/issues/13

So, what about making inlines completely customizable? By this I mean that parser will not try to impose an interpretation on the syntax simply note what's there, e.g., {*a*} is not parsed as bold a, but as *'ed a. This means that we can define new wild operators, as long as they do not conflict with normal writing. I suggest the following characters to be part of the operator span: !?-+&*^%$#@|/=_~: and any combinations of these. So, !! is an operator, @# is an operator, and even @#!#$ is an operator. It's then up to the back end to interpret these suggestions. In html, {* bold *} could be bold, {** strong **} could be strong, {_ em _} could be em, {__ italic __} could be italic, and so on.

I suggest that there are three ways to use the operators, which are already being used in djot today:

  1. {!? a ?!} multi word, notice that the ending operator is reversed, just flair.
  2. !?a single word, and
  3. !?`asd v` verbatim word.

Concerns:

bpj commented 1 year ago

As I just commented in #13 I'm also thinking in terms of allowing doubled delimiters inside curly brackets. I think @jgm makes a good case for disallowing them without curly brackets, but I think a case can be made for using them with curly brackets. However I'm not sure I agree that any sequence of punctuation characters next to curly brackets should be an automatic custom delimiter. Also I'm not sure a proliferation of delimiters is a good idea if they just are a shorthand for spans with attributes.

kalhauge commented 1 year ago

I think its a question of standardization vs customization! A standard format will allow djot to be generally readable, as soon as you open a djot file you know what it does. A customizable format will allow djot to be generally applicable, meaning that in any setting that need writing we can use djot. The two goals are sadly at odds, but ultimately up to the values of the project.

My suggestion would be a customizable parser, but a standardized HTML back-end. Deciding on how the HTML is rendered will guide (but not limit) other renders as they (hopefully) would like to stay compatible.

kalhauge commented 1 year ago

I notice that this will also fix the https://github.com/jgm/djot/issues/125 cotcha, now {--- is the start of a --- span, and {-- is the start of a -- span. To get the required effect we could write {{-- or {{---.