diff --git a/amanuensis/resources/editor.css b/amanuensis/resources/editor.css index 553b356..1944b64 100644 --- a/amanuensis/resources/editor.css +++ b/amanuensis/resources/editor.css @@ -45,6 +45,15 @@ div#editor-right { div#editor-right div.contentblock { margin: 10px 5px 10px 10px; } +div#editor-right p#editor-warnings { + color: #808000; +} +div#editor-right p#editor-errors { + color: #ff0000; +} +span.new { + color: #008000; +} @media only screen and (max-width: 816px) { div#wrapper { max-width: 564px; diff --git a/amanuensis/resources/editor.js b/amanuensis/resources/editor.js index 16d3768..4052bea 100644 --- a/amanuensis/resources/editor.js +++ b/amanuensis/resources/editor.js @@ -5,23 +5,9 @@ function onContentChange() { // 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(" / "); + var citeblockContent = makeCiteblock(parseResult); // 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() + "
"; + var controlContent = checkWarnings(parseResult); // Fill in the content blocks document.getElementById("preview").innerHTML = ( "" + 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; } +function makeCiteblock(parseResult) { + var citeTexts = [] + for (var i = 0; i < parseResult.citations.length; i++) { + var cite = parseResult.citations[i]; + citeTexts.push("[" + cite.id.toString() + "] " + cite.citeTitle); + } + return citeTexts.join(" / "); +} + +function checkWarnings(parseResult) { + var result = { + errors: [], + warnings: [], + }; + if (!parseResult.hasSignature) { + result.warnings.push("Article has no signature."); + } + // Self-citation + // TODO + // Citation targets + // TODO + if (params.citation.min_total != null && + parseResult.citations.length < params.citation.min_total) { + result.errors.push("Article must have a minimum of " + + params.citation.min_total + " citations."); + } + if (params.citation.max_total != null && + parseResult.citations.length > params.citation.max_total) { + result.errors.push("Article cannot have more than " + + params.citation.max_total + " citations."); + } + // TODO + // Word limits + var wordCount = (parseResult.html + // Delete all HTML tags + .replace(/<[^>]+>/g, "") + .trim() + .split(/\s+/) + .length); + if (params.wordLimit.hard != null && wordCount > params.wordLimit.hard) { + result.errors.push("Article must be shorter than " + params.wordLimit.hard + " words."); + } else if (params.wordLimit.soft != null && wordCount > params.wordLimit.soft) { + result.warnings.push("Article should be shorter than " + params.wordLimit.soft + " words."); + } + + var controlContent = ""; + controlContent += "Word count: " + wordCount + "
"; + if (result.errors.length > 0) { + controlContent += "";
+ for (var i = 0; i < result.errors.length; i++) {
+ controlContent += result.errors[i] + "
";
+ }
+ controlContent += "
";
+ for (var i = 0; i < result.warnings.length; i++) {
+ controlContent += result.warnings[i] + "
";
+ }
+ controlContent += "