Coder Social home page Coder Social logo

Inclusion of other djot documents about djot HOT 18 OPEN

tmke8 avatar tmke8 commented on June 12, 2024
Inclusion of other djot documents

from djot.

Comments (18)

toastal avatar toastal commented on June 12, 2024 2

AsciiDoc has level offsets that are really great to use with include. This means the subdocument can start all over with <h1>. This makes authoring and reading easier outside as context of the main document isn't relevant.

from djot.

clbarnes avatar clbarnes commented on June 12, 2024 1

if the start or end line is is in the middle of some structure

I guess inclusions would have to happen early, so it would be a raw text dump. If the inclusion had a triple backtick in it, that would be treated as the start of a fenced code block, even if in the source it was the end of a fenced code block. I don't think this is a problem, really: raw text inclusion is by far the simplest and most predictable thing to do, and if users end up with weird documents, that's no different to them writing weird documents manually.

from djot.

vassudanagunta avatar vassudanagunta commented on June 12, 2024 1

The technical term for this is transclusion.

Though it's for Markdown, the arguments for and functionality supported by IA Writer's transclusion support in v4 added back late 2016 is worth looking at for ideas. They even wrote a spec for it with the hope for community adoption.

from djot.

clbarnes avatar clbarnes commented on June 12, 2024

Also very helpful for tables, in my experience. Asciidoctor allows you to say "this is a TSV", then include a TSV file and have it rendered nicely - for djot I suppose that would best be left to a custom attribute and filter. This means you can generate/edit your data with some external tool better suited for working with such a format. Even generating djot-formatted tables externally and then just having an include would be helpful.

from djot.

bpj avatar bpj commented on June 12, 2024

AsciiDoc has level offsets that are really great to use with include. This means the subdocument can start all over with <h1>.

My Pandoc filter for inclusion can handle that. You do something like this:

``` {format=html plus_hlevel=2}
filename.html
``` 

After the filter has parsed the contents of the included file with Pandoc1 the filter walks the contents of the included document2 and adds the value of the plus_hlevel attribute on the code block to the level of all headings. The added value may of course be negative, but I have as far as I can remember never needed to subtract from the levels of headings in an included file. I also have a filter which only raises/lowers the level of all headings in a document which I have sometimes used to subtract.

Footnotes

  1. There is a function for that in Pandoc’s Lua API

  2. You wrap the content of the doc in a div object and use a method of that object to apply a filter to its content.

from djot.

crlf0710 avatar crlf0710 commented on June 12, 2024

Storing pathnames within text has the usual caveat: Under POSIX systems filenames are not guarantee'd to be valid utf-8 string, while under Windows systems unpaired wtf-16 surrogate code units will be met. Case insensitives and text normalizations are also features of various filesystems. If this feature is included, i'd like to see the rules of whether escaping or forbidding be explicitly chosen upright.

from djot.

clbarnes avatar clbarnes commented on June 12, 2024

I think a note saying that non-UTF-8 filenames can't be addressed and that paths follow the rules of the filesystem the path is pointing at would be fine. Encourage the use of sensible names and filesystems rather than making everyone's lives harder to make things comfortable for those who don't.

from djot.

toastal avatar toastal commented on June 12, 2024

from djot.

dbready avatar dbready commented on June 12, 2024

Similarly, I would like to be able to include segments of non-djot documents.

My specific use case would be referencing source code. If I want to reference a function in an adjacent file, a mechanism to extract specified lines and render them inside a verbatim block. A typical approach to producing examples may iteratively reference small blocks of code throughout the document, and then display the complete file at the end.

Possibly out of scope for core, but wanted to mention it as this is something I am encountering in a project.

from djot.

toastal avatar toastal commented on June 12, 2024

@dbready I can echo that too. Using AsciiDoc to reference code snippets from the code itself is super helpful and easier to keep in sync (just need to remember line numbers).

from djot.

dbready avatar dbready commented on June 12, 2024

Keeping line numbers in sync is definitely a tricky point. My ideal interface would allow for the two workflows:

  • starting line number + [offset line count | final line number] - if only first parameter, implicitly contain rest of file
  • delineated blocks identified by some kind of (optionally named) token

The first workflow is required to annotate real code which cannot be polluted with documentation markup. The second is more convenient for being able to maintain code block references without having to continually keep line numbers synchronized.

from djot.

chrisjsewell avatar chrisjsewell commented on June 12, 2024

Heya, I would also point to https://docutils.sourceforge.io/docs/ref/doctree.html as well here (i.e. what restructuredtext does)
Here, every node in the AST stores both a line number and source attribute.
this allows for later post-processing warnings to point to the specific file and line

from djot.

jgm avatar jgm commented on June 12, 2024

Yes, if we had built-in includes, implementations that store source positions would have to add a source name to the source position.

from djot.

mcookly avatar mcookly commented on June 12, 2024

If the [[...]] syntax is not used for wikilinks (#26), perhaps it could be used here. You could then specify line numbers/offsets using attribute syntax. For example:

[[source-code.abc]]{2 10 .colorized}

would read the file from line 2 through 10 and apply colorized to the included content.

Allowing attributes would also make built-in includes versatile enough for both prose and code, e.g. logseq-esque linking (#231).

from djot.

Omikhleia avatar Omikhleia commented on June 12, 2024

from line 2 through 10

What does it mean, in the general scope of transclusion, if the start or end line is is in the middle of some structure -- say, a div, if the included file is a Djot file?

from djot.

mcookly avatar mcookly commented on June 12, 2024

What does it mean, in the general scope of transclusion, if the start or end line is is in the middle of some structure

I think the transcluded djot source should be isolated from the rest of the inheriting document, if possible -- essentially treating the transcluded source as its own structure.

I guess inclusions would have to happen early, so it would be a raw text dump.

If the transcluded content is its own djot structure, then perhaps it can be left up to the renderer whether or not the source is a raw text dump. This ambiguity could cause a lot of parsing confusion though. Borrowing from image syntax, you might be able to avoid this problem by using [[...]] for isolated transcluded content and ![[...]] for a raw text dump.

from djot.

clbarnes avatar clbarnes commented on June 12, 2024

I suppose some processing may have to occur in the transcluded block for resolving paths - if a/main.djot transcludes a/b/c/inner.djot, which refers to an image using the local path ./img.jpeg, where does the document look for the image?

from djot.

mcookly avatar mcookly commented on June 12, 2024

where does the document look for the image?

If the AST nodes store which files they come from, then child nodes with relative paths can inherit from the parent node's path (I think). So a parser/renderer would look for the image in a/b/c/img.jpeg. How filepaths are resolved could be up to the renderer though, but I don't like this possibility since it diminishes djot's interoperability.

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.