raito icon indicating copy to clipboard operation
raito copied to clipboard

[feat] provide way to use include

Open mckaygerhard opened this issue 2 years ago • 1 comments

in wikimedia, and dokuwiki there's a way to renders a page inside another.. just something like "frame" tag does in html..

please provide a way to do an include like that, example

page1.md:

# title

lorem ipsum

include(page2.md)

page2.md

more lorem ipsum

expected result

TITLE

lorem ipsum

more lorem ipsum

mckaygerhard avatar Mar 30 '22 17:03 mckaygerhard

Heya. I think you're talking about Transclusion functionality.

Raito uses marked.js library for .md rendering, so we need to proceed to their docs: https://marked.js.org/using_advanced And then it comes to extensions: https://marked.js.org/using_pro


But that way will be the hard way. Instead you can think of some dirty little snippet to do the right job... First, modify configuration to store regex that will be used to modify markdown file contents:

<!-- Configure me! -->
<script>
    const config = {
        "name": "Wiki",
        "root": "", // Eg: "/raito/" 
        "elements": ["navbar", "github_ribbon"],
        "errorMessage": "Page not found",
        "markdownTransclusionRegex": /{{([\w].+[\.md])}}/g
    }
</script>

Then, you can modify renderMD function to be something like this:

const renderMD = async (path) => {
    const res = await fetch(`${config.root}${path}.md`);
    if (res.status != 200) return;
    let markdown = await res.text();

    if (config.markdownTransclusionRegex) {
        const renderTMD = [...markdown.matchAll(config.markdownTransclusionRegex)];
        for(let regexMatch of renderTMD) {
            let resT = await fetch(config.root + regexMatch[1]);
            if (resT.status != 200) return;
            markdown = markdown.replace(regexMatch[0], await resT.text());
        }
    }

    return marked.parse(markdown,
        {
            baseUrl: "#/",
            highlight: (code) => hljs.highlightAuto(code).value,
        });
}

scsmash3r avatar Apr 13 '22 15:04 scsmash3r

Interesting idea, we could actually rival will full-fleged CMSes with this ! And it seems feasible statically.

Will work on a proof of concept

arnaudsm avatar Jul 12 '23 21:07 arnaudsm

@arnaudsm the explanation of @scsmash3r are not complete and really dont catch the concept..

in any case i will explain in other way

i have a wiki page that only:

## my page wiki

include(anotherpage)

with my idea will display

my page wiki

my content

cos the wiki page "anotherpage" has this:

my content

mckaygerhard avatar Jul 13 '23 18:07 mckaygerhard

ok posted feedback:

  • page1.md
  • page2.md
  • dir/page3.md
  • dir/page4.md

GOT GREAT RESULTS:

  • using include(page2.md) worked from root page1.md
  • using include(dir/page3.md) worked from root page1.md
  • renders page4 using include(dir/page4.md) inside page3 but with include(dir/page3.md) worked from root page1.md, and this was interesting result! wow!

BUT, it also got some interesting features:

  • it also renders the page 3 worked from root page1.md using include(page2.md) and with contents of page2 as include(dir/page3.md)
  • using include(../page1.md) worked from root page3.md and was an unexpected result pretty interesting and featured also

LAST

  • in root app (index.html) i used include(../pageuoutside.md) from the root web server doc dir, to get a file outside of the root permitted web app dir base (/var/www/html), and fortunately give me:
failed to load resource: the server responded with a status of 404 (Not Found)

The recursion maybe could be a problem (maybe, i dont see a immediate problem right now) but it seems its a featured unexpected good result, INCREDIBLE WORK!

mckaygerhard avatar Jul 15 '23 02:07 mckaygerhard