diff --git a/amanuensis/resources/editor.css b/amanuensis/resources/editor.css new file mode 100644 index 0000000..553b356 --- /dev/null +++ b/amanuensis/resources/editor.css @@ -0,0 +1,64 @@ + +html, body { + height: 100%; + margin: 0px; +} +div#wrapper { + max-width: 1128px; + height: 100%; + display:flex; + flex-direction: row; + align-items: stretch; +} +div.column { + width: 50%; +} +div#editor-left { + display: flex; + align-items: stretch; +} +div#editor-left div.contentblock { + display: flex; + flex-direction: column; + margin: 10px 10px 10px 5px; + width: 100%; + padding: 5px; +} +div#editor-left div#editor-header { + margin: 5px; + display: flex; + justify-content: space-between; +} +div#editor-left input#editor-title { + font-size: 2em; + margin: 5px; +} +textarea#editor-content { + margin: 5px; + resize: none; + flex-grow: 1; + width: initial; +} +div#editor-right { + overflow-y: scroll; +} +div#editor-right div.contentblock { + margin: 10px 5px 10px 10px; +} +@media only screen and (max-width: 816px) { + div#wrapper { + max-width: 564px; + margin: 0 auto; + padding: inherit; + flex-direction: column; + } + div.column { + width: 100%; + } + div#editor-left { + height: 100%; + } + div#editor-right { + overflow-y: inherit; + } +} diff --git a/amanuensis/resources/editor.js b/amanuensis/resources/editor.js new file mode 100644 index 0000000..16d3768 --- /dev/null +++ b/amanuensis/resources/editor.js @@ -0,0 +1,152 @@ +function onContentChange() { + // Get the new content + var articleTitle = document.getElementById("editor-title").value; + var articleBody = document.getElementById("editor-content").value; + // Pass the draft text to the parser to get the preview html and citations + var parseResult = parseLexipythonMarkdown(articleBody); + // Build the citation block + var citeTexts = [] + for (var i = 0; i < parseResult.citations.length; i++) { + var cite = parseResult.citations[i]; + citeTexts.push("[" + cite.id.toString() + "] " + cite.citeTitle); + } + var citeblockContent = citeTexts.join(" / "); + // Compute warnings and build the control block + var flagMissingSignature = !parseResult.hasSignature; + var wordCount = (parseResult.html + // Delete all HTML tags + .replace(/<[^>]+>/g, "") + .trim() + .split(/\s+/) + .length); + var controlContent = ""; + controlContent += "
Signature: " + (!flagMissingSignature).toString() + "
"; + controlContent += "Word count: " + wordCount.toString() + "
"; + // Fill in the content blocks + document.getElementById("preview").innerHTML = ( + "" + para.slice(1) + "
"; + result.hasSignature = true; + } else { + para = "" + para + "
\n"; + } + result.html += para; + } + if (citationList.length > 0) { + content += "The following articles will be cited:
\n"; + for (var i = 0; i < citationList.length; i++) { + content += "" + citationList[i] + "
\n"; + } + } + // Calculate approximate word count + // var wordCount = text.trim().split(/\s+/).length; + // if (text.trim().length < 1) + // wordCount = 0; + // content += "Article length: approx. " + wordCount + " words
"; + + return result; +} + +// Parse the article content and update the preview pane + + +// function download() { +// var articlePlayer = document.getElementById("article-player").value; +// var articleTurn = document.getElementById("article-turn").value; +// var articleTitle = document.getElementById("article-title").value; +// var articleBody = document.getElementById("article-body").value; +// var articleText = +// "# Player: " + articlePlayer + "\n" + +// "# Turn: " + articleTurn + "\n" + +// "# Title: " + articleTitle + "\n" + +// "\n" + +// articleBody; +// var articleFilename = articleTitle.toLowerCase().replace(/[^a-z0-9- ]/g, "").replace(/ +/g, "-"); +// var downloader = document.createElement("a"); +// downloader.setAttribute("href", "data:text/plain;charset=utf-8," + encodeURIComponent(articleText)); +// downloader.setAttribute("download", articleFilename); +// if (document.createEvent) { +// var event = document.createEvent("MouseEvents"); +// event.initEvent("click", true, true); +// downloader.dispatchEvent(event); +// } else { +// downloader.click(); +// } +// } + +window.onload = function() { + document.getElementById("editor-content").value = "\n\n" + params.defaultSignature; + this.onContentChange(); +}; + +window.addEventListener("beforeunload", function(e) { + var content = document.getElementById("editor-content").value + var hasText = content.length > 0 && content != "\n\n" + params.defaultSignature; + if (hasText) { + e.returnValue = "Are you sure?"; + } +}); + +window.addEventListener("keydown", function(event) { + if (event.ctrlKey || event.metaKey) + { + if (String.fromCharCode(event.which).toLowerCase() == 's') + { + event.preventDefault(); + document.getElementById("preview").innerHTML += "wrong
"; + } + } +}); \ No newline at end of file diff --git a/amanuensis/server/lexicon.py b/amanuensis/server/lexicon.py index 18ab352..460ac50 100644 --- a/amanuensis/server/lexicon.py +++ b/amanuensis/server/lexicon.py @@ -134,4 +134,10 @@ def get_bp(): def stats(name): return render_template('lexicon/statistics.html') + @bp.route('/session/editor/', methods=['GET']) + @lexicon_param + @player_required + def editor(name): + return render_template('lexicon/editor.html') + return bp diff --git a/amanuensis/templates/lexicon/editor.html b/amanuensis/templates/lexicon/editor.html new file mode 100644 index 0000000..2c84dce --- /dev/null +++ b/amanuensis/templates/lexicon/editor.html @@ -0,0 +1,52 @@ +{% set characters = g.lexicon.get_characters_for_player(current_user.id) %} +{% if not characters %} +{% set characters = [g.lexicon.character.default ] %} +{% endif %} + + + + + +This editor requires Javascript to function.
+[1]
+Article length:
+