Skip to content

Markdown and HTML filters#1

Open
klorenz wants to merge 17 commits intopartageit:masterfrom
klorenz:master
Open

Markdown and HTML filters#1
klorenz wants to merge 17 commits intopartageit:masterfrom
klorenz:master

Conversation

@klorenz
Copy link

@klorenz klorenz commented Jan 14, 2016

for beeing able to publish gollum wiki pages, I need a preprocess and postprocess filter like gollum has. It works with a filter stack applying first filters to the markdown pages, and later it postprocesses filters to generated HTML content.

I have not tested everything (maybe we work out together some testing framework, e.g. based on jasmine), but it is working at least with commands.

e.g. I am having a simple README.md containing a [[link]] and following vegetables.json:

{
    "tags": {
        "globalTitle": "my site",
        "menu": [
            {
                "uri": "index.html",
                "label": "Homepage"
            }
        ]
    },
    "filterMarkdown": [
        "perl -n -e 's/\\[\\[(.*?)\\|(.*?)\\]\\]/[$1]($2.html)/g;s/\\[\\[(.*?)\\]\\]/[$1]($1.html)/g;print'"
    ]
}

this replaces all [[links]] to [links](links.html).

From design (not yet tested) you could even do:

{
   "filterMarkdown": [
     { 
        "require": "/path/to/file.js"
     },
   ],
   "filterHTML": [
     { 
        "require": "/path/to/file.js"
     }
   ],
}

where file.js is something like:

module.exports = function(opts) {
   if (opts.markdown) {
       var md = opts.markdown;
       return md.replace(/sometext/g, "othertext");
   } else if (opts.html) {
      return opts.html.replace(/foo/g, "bar");
  }
}

So you can use the same function for HTML transformation.

@klorenz
Copy link
Author

klorenz commented Jan 14, 2016

Do not yet merge this, I am adding some more hooks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant