Skip to content

Instantly share code, notes, and snippets.

@gabestein
Last active May 8, 2020 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabestein/16fd6244f88625c0ea02e044a22d4ac5 to your computer and use it in GitHub Desktop.
Save gabestein/16fd6244f88625c0ea02e044a22d4ac5 to your computer and use it in GitHub Desktop.
This is my gist.
/***
Can take generated HTML export from PubPub and convert to other formats with proper footnotes and citations
Requires pandoc (probably from brew), pandoc-filter from NPM
pandoc -s <source.html> -f html -t <format> -o <otput.format> --filter ./pubpub-filter.js
***/
const pandoc = require('pandoc-filter');
const Cite = pandoc.Cite;
const Str = pandoc.Str;
const Div = pandoc.Div;
const Note = pandoc.Note;
const Plain = pandoc.Plain;
const Para = pandoc.Para;
const RawBlock = pandoc.RawBlock;
const Span = pandoc.Span;
function action(type,value,format,meta) {
if (type === 'Div' || type === 'Span') {
const [[ids, classes, kvs], contents] = value;
if(classes.includes('citation-wrapper') || classes.includes('footnote-wrapper')) {
console.error('\ncontents in:\n', JSON.stringify(contents), '\n');
/* all inline */
//const new_contents = Span(["",[],[]],[Note([Plain(contents)])]);
/* all block */
const new_contents = Plain([Note(contents)]);
/* block --> inline */
/* not functioning in all cases? */
//const new_contents = [Plain([Span(["",[],[]],[Note(contents)])])];
console.error('\ncontents out:\n',JSON.stringify(new_contents),'\n');
return new_contents;
}
if(classes.includes('count-wrapper')) { return [] };
//if(classes.includes('render-wrapper')) { /* convert to inline? */ }
}
}
pandoc.stdio(action);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment