-
-
Save gabestein/16fd6244f88625c0ea02e044a22d4ac5 to your computer and use it in GitHub Desktop.
This is my gist.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*** | |
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