Giter VIP home page Giter VIP logo

Comments (3)

lcnbr avatar lcnbr commented on July 21, 2024

Thinking about it more, it seems I want latex macro-like functionality, but with a semantic focus more than a typographical one. The macro expansion could be handled by any sort of filter, but having a predefined syntax in the spec means anyone writing such a filter would have a simple node in the AST, that is well defined, and standardized, with basic functionality like text replacement covered by the base syntax. I feel like this gives the end user incredible flexibility, which is hard to achieve in any markdown flavor. Additionally, it opens the space up to text-based syntax, that crucially is user-defined, and thus not English first.

from djot.

jgm avatar jgm commented on July 21, 2024

If you look at my motivating article "Beyond Markdown," you'll see that I envision this kind of extension through four basic constructions that are already in djot:

  • verbatim spans with attributes
  • verbatim blocks with attributes
  • formatted spans with attributes
  • formatted blocks with attributes

With these four things and filters, you have quite a lot of flexibility without any additional syntax.

from djot.

bpj avatar bpj commented on July 21, 2024

@lcnhb What do you want which you can't get with possibly nested spans and divs and filters?
I agree that it would be nice if there were list-like containers so that

[foo][bar][baz]{.quux}

were treated as equivalent to

[[foo]{}[bar]{}[baz]{}]{.quux}

but it is indistinguishable from a reference link followed by a span, so perhaps some separator character like

[foo]+[bar]+[baz]{.quux}

which could be extended to divs too:

{.quux}
:::
foo
+:::
bar
+:::
baz
:::

An actual macro functionality where you can define macros in-text leads to clutter and a lot of (for humans) confusion between what is definitions and what is content, and since I use Pandoc/Markdown in preference to LaTeX to get away from not seeing the text for all the markup I advice strongly against such.

What I do use is my own string templating (pre)processor (which I will put online as soon as I have got some decent documentation written) which takes a hint from lightweight markup languages in preferring punctuation to keywords and is vaguely similar to Bash parameter expansion, e.g.:

  • $(foo) or $foo

    Inserts the value of variable foo.

  • $<foo bar> $<bæz>

    Inserts variable values but variable names are not limited to ASCII alphanumerics, underscores and hyphens.

  • $(foo?|bar) or $(foo ?| (bar) )

    Inserts the value of variable foo or if it is empty the string "bar".

  • $(foo??bar) or $( foo ?? (bar) )

    Inserts the string "bar" if the variable foo is non-empty.

  • $(foo?!bar) or $( foo ?! (bar) )

    Inserts the string "bar" if the variable foo is empty.

  • $( foo ?? $bar ?! (no $game) )

    Inserts the value of variable bar if variable foo is non-empty, or the string "no X", where X is the value of the variable game, if foo is empty.

  • $:foo( $bar, (my $game), 42, (ba@<331>) )

    Inserts the return value of calling the function foo with four arguments, where @<331> aka @<0x14b> is replaced with the Unicode character "ŋ" LATIN SMALL LETTER ENG.

Now the difference between the template processor and a macro processor is of course that with the former variables and functions are defined outside the template file by a script which imports the template engine class and passes the functions to the constructor as a data structure of function references written in the same language as the template engine. Variables are passed as a data structure of strings/numbers/booleans to the template expansion method and/or the constructor. Templates can be passed to the expansion method either as strings or as pre-parsed objects, allowing the calling program to parse a template once and fill it in several times with different data sets.

The templating engine is separate from Pandoc; it can be used for any text to be further processed with any program, but since it is written in pure MoonScript/Lua it can also be used from inside a Pandoc filter, typically defining templates as verbatim spans or blocks, either in the body or the metadata, which after expansion are passed to the Pandoc Lua API's read function to be converted to AST fragments which are then inserted into the document body. It is still separate from the markup language as parsed by Pandoc; it can be used within Markdown or djot input, and might make sense with other input formats too.
There is a "light" implementation with a subset of the functionality roughly equivalent to what I showed above which is small enough to inline into a Pandoc filter.

from djot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.