Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Markdown and HTML filters #1

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open

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.

None yet

1 participant