add an external md file to a php page

… and, of course see it as html, with the same graphical appearance of any other web text.

A way can be use a very light javascript, md-block.js, di Lea Verou.

Then you can add a function to your php website, like the following:

<?php
/* to call a file Markdown from a given folder */

function scheda_md($file)
{
    global $yourwebsite;

    $file = basename($file);

    return '<md-block src="' .
           $yourwebsite .
           '/the-path/where-are-md-files/from-yourwebsite-root' .
           htmlspecialchars($file, ENT_QUOTES, 'UTF-8') .
           '"></md-block>';
}
?>

And in the page where you want to show that md file you can use this code:

<?= scheda_md('the-md-name.md') ?>

add footnotes to embedded md file

I mean notes that should be correctly shown both in a webpage and in the standalone md file.
You have to modify the js (md-bloc.js), as you can see in the linked file.

In this way you can use the md syntax, such as:

[^1] (for the anchor) and
[^1]: for the footnote.

External markdown file in WordPress

If you want keep an external markdown file and include it in a WordPress page, you can follow these steps:

  • add a js file, such as md-block.js, in your js theme folder (typically /wp-content/themes/your-theme/js/ )
  • modify the functions.php file, in your root theme folder,. adding this code:
// per markdown BEGIN

function carica_md_block() {
    wp_enqueue_script(
        'md-block',
        get_stylesheet_directory_uri() . '/js/md-block.js',
        array(),
        null,
        true
    );
}
add_action('wp_enqueue_scripts', 'carica_md_block');

add_filter('script_loader_tag', function($tag, $handle, $src) {
    if ($handle === 'md-block') {
        return '<script type="module" src="' . esc_url($src) . '"></script>';
    }
    return $tag;
}, 10, 3);

function shortcode_scheda_md($atts) {
    $atts = shortcode_atts(array(
        'file' => ''
    ), $atts);

    $file = basename($atts['file']);

    if (empty($file) || pathinfo($file, PATHINFO_EXTENSION) !== 'md') {
        return '';
    }

    $url = content_url('/uploads/some-path/' . rawurlencode($file));

    return '<md-block src="' . esc_url($url) . '"></md-block>';
}
add_shortcode('scheda_md', 'shortcode_scheda_md');

// per markdown END
  • you can put your md files in the path above set: /uploads/some-path/ . Note that the folder some-path could be a symlinked one, from your local PC.
  • in the wordpress page when you want include a md file you can write,
    • using HTML (customized), [scheda_md file="the-name-of-the-file.md"],
    • or the code visualizaztion: something like[scheda_md]the-name-of-the-file.md[/scheda_md]
  • where that file, obviously, should be in /some-path/ folder.

Espanso

A very useful feature of espanso (a text expander also for wayland) is the possibility to convert the clipboard content to lowercase (with ::low) or to uppercase (with ::up).

The Markdown benefits

The Markdown format It is a format that guarantees the maximum of graphic rendering with the minimum of code. Why is this important?

A rich graphic rendering, on the one hand, is a value because the things that are written (and then they must be correctly readable) do not all have the same importance. And, on the other hand, the minimal use of the code helps to reduce the size of the file, occupying as little space as possible on the device. Moreover, Markdown helps also to modify directly and easily the code, since it is an extremely “clean” code and very similar to its graphic rendering.

titles

A title must hit more than the body of the text. And a main title must hit more than secondary titles. A way to do this is a different size of characters. Markdown can do this.

the TOC

The use of titles is also useful for “browsing” quickly in a document, jumping from one title to another, without having to flow the whole body of the text. A good text viewer is able to provide a TOC (Table of Content) which allows you to browse quickly between the parts of the document (characterized by higher or lesser level titles).

text formatting

But the body of the text is also important to highlight what is most important from what is less: bold and italics are ways to do it.

blockquotes

Then it is good to be able to distinguish between what the author of the document and the blocks of text said by other authors (i.e. long citations) writes, and for this there is the blockquote, which is good is also graphically distinct from the rest of the body of the text.

Markdown editor

Unfortunately same of the best MD editors have critical limitations

  • Dynalist, i.g., would be an excellent md editor, but it forces you to use an online account (that means: a) you must be connected to the internet, and b) you share your data with Dynalist, and so your privacy goes away).
  • VNote too would be a good md editor, but it forces you to use its proprietary format (with only files in its own folder), and so you can’t open any existing md file.
  • LogSeq is very slow in starting, doesn’t provide a wysing editor, can’t edit long files, and, as the other above editors, it don’t let you open, modify and save existing md files.
  • Joplin is a bite better, but it too don’t let open, modify and save existing md files: you must use its folder, and its proprietary format.
  • Siyuan is another app that force you to use its folder and its proprietary format.
  • MdSilo is not a bad program, but is very basic. Its wysing is alternative to the source code. Re-open a file is not easy at all. Styling the editor impossible.
  • Markflowy: not too bad, open source, and wysing; but you cannot see the source code, and most important, you cannot open the file you want, neither from outside the app, nor inside it.
  • Obsidian (not open source) was not able to open or save any md file, even though it uses markdown. Now it can do both open and save a md file, in a very interesting wysing mode, but it forces you within its narrow proprietary boundaries.
  • MarkText would be quite good wysing md editor, quite similar to Typora, but unfortunately it is discontinued.
  • Typora is the best md wysing editor: it support css customization and symlinks, you can easily open and save your md existing files (wherever they are). But is is not open source, but a pay app.