On Wed, Oct 28, 2015 at 10:36 AM, Matt Price <[email protected]> wrote:
>
> That does seem to be an issue, but I bet it wouldn't be too hard to fix.
> Currently outputformat is hardcoded on line 94 of lib/citeServer.js; I'm a
> little slow at reading JS but I think replacing line 259 with a switch
> statement analogous to the one for responseformat at line 291 would allow
> one to use the full capacities of citeproc.js. I think the best route
> would probably be to submit a patch to citeproc.js adding an org-mode
> output format, propagating that up to citeproc-node, submitting a second
> patch to citeproc-node, and then writing the org-internal functions
> properly. We might also want to add an additional responseformat option.
>
>> Matt
>>
>
>
here is a very half-assed aproach that adds an org-mode outputformat to
citeproc. it's incomplete but does much of wha it ought to. some of the
elements I left in html b/c I'm not sure how they oughtto be handled in
org. e.g., how do we handle smallcaps?
(this is a patch to citeproc-node, so requires installing the repo from
github first).
diff --git a/lib/citeServer.js b/lib/citeServer.js
index 691ca78..a5d82c7 100644
--- a/lib/citeServer.js
+++ b/lib/citeServer.js
@@ -91,7 +91,7 @@ var defaultCiteserverConfig = {
var defaultRequestConfig = {
bibliography: '1',
citations: '0',
- outputformat: 'html',
+ outputformat: 'org',
responseformat: 'json',
locale: 'en-US',
style: 'chicago-author-date',
diff --git a/lib/citeproc.js b/lib/citeproc.js
index 08a8008..8622533 100644
--- a/lib/citeproc.js
+++ b/lib/citeproc.js
@@ -13140,6 +13140,106 @@ CSL.Output.Formats.prototype.html = {
return "<a href=\"http://dx.doi.org/" + str + "\">" + str + "</a>";
}
};
+
+CSL.Output.Formats.prototype.org = {
+ "text_escape": function (text) {
+ if (!text) {
+ text = "";
+ }
+ return text.replace(/&/g, "&")
+ .replace(/</g, "<")
+ .replace(/>/g, ">")
+ .replace(" ", "  ", "g")
+ .replace(CSL.SUPERSCRIPTS_REGEXP,
+ function(aChar) {
+ return "<sup>" + CSL.SUPERSCRIPTS[aChar] + "</sup>";
+ });
+ },
+ "bibstart": "* Bibliography\n",
+ "bibend": "\n",
+ "@font-style/italic": "/%%STRING%%/",
+ "@font-style/oblique": "/%%STRING%%/",
+ "@font-style/normal": "%%STRING%%",
+ "@font-variant/small-caps": "<span style=\"font-variant:small-caps;\">%%STRING%%</span>",
+ "@passthrough/true": CSL.Output.Formatters.passthrough,
+ "@font-variant/normal": false,
+ "@font-weight/bold": "*%%STRING%%*",
+ "@font-weight/normal": false,
+ "@font-weight/light": false,
+ "@text-decoration/none": false,
+ "@text-decoration/underline": "_%%STRING%%_",
+ "@vertical-align/sup": "^{%%STRING%%}",
+ "@vertical-align/sub": "_{%%STRING%%}",
+ "@vertical-align/baseline": false,
+ "@strip-periods/true": CSL.Output.Formatters.passthrough,
+ "@strip-periods/false": CSL.Output.Formatters.passthrough,
+ "@quotes/true": function (state, str) {
+ if ("undefined" === typeof str) {
+ return state.getTerm("open-quote");
+ }
+ return state.getTerm("open-quote") + str + state.getTerm("close-quote");
+ },
+ "@quotes/inner": function (state, str) {
+ if ("undefined" === typeof str) {
+ return "\u2019";
+ }
+ return state.getTerm("open-inner-quote") + str + state.getTerm("close-inner-quote");
+ },
+ "@quotes/false": false,
+ "@cite/entry": function (state, str) {
+ return state.sys.wrapCitationEntry(str, this.item_id, this.locator_txt, this.suffix_txt);
+ },
+ "@bibliography/entry": function (state, str) {
+ var insert = "";
+ if (state.sys.embedBibliographyEntry) {
+ insert = state.sys.embedBibliographyEntry(this.item_id) + "\n";
+ }
+ return " \n" + str + "\n" + insert;
+ },
+ "@display/block": function (state, str) {
+ return "\n\n <div class=\"csl-block\">" + str + "</div>\n";
+ },
+ "@display/left-margin": function (state, str) {
+ return "\n <div class=\"csl-left-margin\">" + str + "</div>";
+ },
+ "@display/right-inline": function (state, str) {
+ return "<div class=\"csl-right-inline\">" + str + "</div>\n ";
+ },
+ "@display/indent": function (state, str) {
+ return "<div class=\"csl-indent\">" + str + "</div>\n ";
+ },
+ "@showid/true": function (state, str, cslid) {
+ if (!state.tmp.just_looking && ! state.tmp.suppress_decorations) {
+ if (cslid) {
+ return "<span class=\"" + state.opt.nodenames[cslid] + "\" cslid=\"" + cslid + "\">" + str + "</span>";
+ } else if ("string" === typeof str) {
+ var prePunct = "";
+ if (str) {
+ var m = str.match(CSL.VARIABLE_WRAPPER_PREPUNCT_REX);
+ prePunct = m[1];
+ str = m[2];
+ }
+ var postPunct = "";
+ if (str && CSL.SWAPPING_PUNCTUATION.indexOf(str.slice(-1)) > -1) {
+ postPunct = str.slice(-1);
+ str = str.slice(0,-1);
+ }
+ return state.sys.variableWrapper(this.params, prePunct, str, postPunct);
+ } else {
+ return str;
+ }
+ } else {
+ return str;
+ }
+ },
+ "@URL/true": function (state, str) {
+ return "<a href=\"" + str + "\">" + str + "</a>";
+ },
+ "@DOI/true": function (state, str) {
+ return "<a href=\"http://dx.doi.org/" + str + "\">" + str + "</a>";
+ }
+};
+
CSL.Output.Formats.prototype.text = {
"text_escape": function (text) {
if (!text) {