metanorma / metanorma-plugin-lutaml

Metanorma plugin: access LutaML objects from within a Metanorma document
BSD 2-Clause "Simplified" License
1 stars 1 forks source link

Update relative file paths in fetched remarks #6

Open opoudjis opened 3 years ago

opoudjis commented 3 years ago

The relative file paths, in the asciidoctor of the remarks extracted by lutaml from expressir, need to be updated to reflect the calling environment. So:

[lutaml, ../../../resources/action_schema/action_schema.exp, repo]

is fetching a line containing:

image::action_schemaexpg1.xml[]

Something needs to update that URL, so that the expression reads: image::../../../resources/action_schema/action_schemaexpg1.xml[]

This means:

If the relative path is, say, ../../x, it would turn into ../../../resources/action_schema/../../x

You must not update absolute paths, which are recognised as follows:

^[^/:]+://|^[A-Z]:/ (e.g. file:///, http://, c:/)

The paths to be so updated are:

So, in sum:

\b(link|image|video|audio|include)(?![^/:]+://|[A-Z]:/)(?<link>[^\[]+)\[

I am ignoring icon:[] macros, since they are assumed to be fixed to one directory for an asciidoc document (https://docs.asciidoctor.org/asciidoc/latest/macros/icons/), and we don't process them currently anyway.

I am ignoring the link attribute of images, because that would be extremely difficult to deal with via regexes, and because that is assumed to be an absolute link by default anyway.

ronaldtse commented 3 years ago

The relative file paths, in the asciidoctor of the remarks extracted by lutaml from expressir, need to be updated to reflect the calling environment. So:

[lutaml, ../../../resources/action_schema/action_schema.exp, repo]

is fetching a line containing:

image::action_schemaexpg1.xml[]

Something needs to update that URL, so that the expression reads: image::../../../resources/action_schema/action_schemaexpg1.xml[]

Wouldn't it be better to allow the user to have the image::... path manually specified to the path they want?

Imagine that you have a different source path for images that is separate from the schema path.

Maybe you want to have the "context path" available as a separate variable inside that context? e.g. {{ context_path }} here stands for ../../../resources/action_schema.

opoudjis commented 3 years ago

So a separate assets directory variable?

The only way that would be acceptable is as a separate and optional parameter to the lutaml macro. The behaviour implemented is fully appropriate as a default.

opoudjis commented 3 years ago

For now, we are addressing this by using absolute paths, when we iterate through multiple schemas. Highly desirable to make them relative paths relative to the embedding document, so that the document can stay portable. This only impacts the asciidoc; we are using data uri encoding for the XML output.