-
Notifications
You must be signed in to change notification settings - Fork 534
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #509 from openannotation/clean-up-markdown-tags
Clean up markdown and tags modules
- Loading branch information
Showing
12 changed files
with
425 additions
and
345 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
.. default-domain: js | ||
annotator.ui.markdown package | ||
============================= | ||
|
||
.. function:: annotator.ui.markdown.renderer(annotation) | ||
|
||
A renderer for the :class:`~annotator.ui.viewer.Viewer` which interprets | ||
annotation text as `Markdown`_ and uses the `Showdown`_ library if present in | ||
the page to render annotations with Markdown text as HTML. | ||
|
||
.. _Markdown: https://daringfireball.net/projects/markdown/ | ||
.. _Showdown: https://github.com/showdownjs/showdown | ||
|
||
**Usage**:: | ||
app.include(annotator.ui.main, { | ||
viewerRenderer: annotator.ui.markdown.renderer | ||
}); | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
.. default-domain: js | ||
annotator.ui.tags package | ||
========================= | ||
|
||
.. function:: annotator.ui.tags.viewerExtension(viewer) | ||
|
||
An extension for the :class:`~annotator.ui.viewer.Viewer` which displays any | ||
tags stored as an array of strings in the annotation's ``tags`` property. | ||
|
||
**Usage**:: | ||
app.include(annotator.ui.main, { | ||
viewerExtensions: [annotator.ui.tags.viewerExtension] | ||
}) | ||
|
||
|
||
.. function:: annotator.ui.tags.editorExtension(editor) | ||
|
||
An extension for the :class:`~annotator.ui.editor.Editor` which allows | ||
editing a set of space-delimited tags, retrieved from and saved to the | ||
annotation's ``tags`` property. | ||
|
||
**Usage**:: | ||
app.include(annotator.ui.main, { | ||
viewerExtensions: [annotator.ui.tags.viewerExtension] | ||
}) | ||
|
||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,41 @@ | ||
/*package annotator.ui.markdown */ | ||
"use strict"; | ||
|
||
var util = require('../util'); | ||
|
||
var g = util.getGlobal(); | ||
var _t = util.gettext; | ||
|
||
function markdown() { | ||
var converter = null; | ||
|
||
/** | ||
* function:: renderer(annotation) | ||
* | ||
* A renderer for the :class:`~annotator.ui.viewer.Viewer` which interprets | ||
* annotation text as `Markdown`_ and uses the `Showdown`_ library if present in | ||
* the page to render annotations with Markdown text as HTML. | ||
* | ||
* .. _Markdown: https://daringfireball.net/projects/markdown/ | ||
* .. _Showdown: https://github.com/showdownjs/showdown | ||
* | ||
* **Usage**:: | ||
* | ||
* app.include(annotator.ui.main, { | ||
* viewerRenderer: annotator.ui.markdown.renderer | ||
* }); | ||
*/ | ||
exports.renderer = function renderer(annotation) { | ||
var convert = util.escapeHtml; | ||
|
||
if (g.Showdown && typeof g.Showdown.converter === 'function') { | ||
converter = new g.Showdown.converter(); | ||
convert = new g.Showdown.converter().makeHtml; | ||
} else { | ||
console.warn(_t("To use the Markdown plugin, you must" + | ||
" include Showdown into the page first.")); | ||
console.warn(_t("To use the Markdown plugin, you must " + | ||
"include Showdown into the page first.")); | ||
} | ||
|
||
// Converts provided text into markdown. | ||
// | ||
// text - A String of Markdown to render as HTML. | ||
// | ||
// Examples | ||
// | ||
// plugin.convert('This is _very_ basic [Markdown](http://daringfireball.com)') | ||
// # => Returns "This is <em>very<em> basic <a href="http://...">Markdown</a>" | ||
// | ||
// Returns HTML string. | ||
function convert (text) { | ||
text = util.escapeHtml(text || ''); | ||
return converter ? converter.makeHtml(text) : text; | ||
if (annotation.text) { | ||
return convert(annotation.text); | ||
} else { | ||
return "<i>" + _t('No comment') + "</i>"; | ||
} | ||
|
||
return { | ||
convert: convert | ||
}; | ||
} | ||
|
||
exports.markdown = markdown; | ||
}; |
Oops, something went wrong.