diff --git a/nyaa/forms.py b/nyaa/forms.py index ba0ad60..334031f 100644 --- a/nyaa/forms.py +++ b/nyaa/forms.py @@ -168,7 +168,7 @@ class EditForm(FlaskForm): information = StringField('Information', [ Length(max=255, message='Information must be at most %(max)d characters long.') ]) - description = TextAreaField('Description (markdown supported)', [ + description = TextAreaField('Description', [ Length(max=10 * 1024, message='Description must be at most %(max)d characters long.') ]) @@ -222,7 +222,7 @@ class UploadForm(FlaskForm): information = StringField('Information', [ Length(max=255, message='Information must be at most %(max)d characters long.') ]) - description = TextAreaField('Description (markdown supported)', [ + description = TextAreaField('Description', [ Length(max=10 * 1024, message='Description must be at most %(max)d characters long.') ]) diff --git a/nyaa/static/css/main.css b/nyaa/static/css/main.css index 4d70ea0..32e96a3 100644 --- a/nyaa/static/css/main.css +++ b/nyaa/static/css/main.css @@ -349,3 +349,19 @@ a.text-purple:hover, a.text-purple:active, a.text-purple:focus { color: #a760e0; .torrent-file-list .file-size { font-weight: bold; } + +.header-anchor { + padding-left: 0.5em; + visibility: hidden; + display: none; +} + +h1:hover .header-anchor, +h2:hover .header-anchor, +h3:hover .header-anchor, +h4:hover .header-anchor, +h5:hover .header-anchor, +h6:hover .header-anchor { + visibility: visible; + display: inline-block; +} diff --git a/nyaa/static/js/main.js b/nyaa/static/js/main.js index 9fd1a5d..7f6c48e 100644 --- a/nyaa/static/js/main.js +++ b/nyaa/static/js/main.js @@ -145,28 +145,46 @@ document.addEventListener("DOMContentLoaded", function(event) { } }); +var markdownOptions = { + html : false, + breaks : true, + typographer: true +} +var markdown = window.markdownit(markdownOptions); +markdown.renderer.rules.table_open = function (tokens, idx) { + // Format tables nicer (bootstrap). Force auto-width (default is 100%) + return ''; +} + // Initialise markdown editors on page document.addEventListener("DOMContentLoaded", function() { - var markdownEditors = Array.prototype.slice.call(document.querySelectorAll('.markdown-editor')); + var markdownEditors = Array.prototype.slice.call(document.querySelectorAll('.markdown-editor')); - markdownEditors.forEach(function (markdownEditor) { - var fieldName = markdownEditor.getAttribute('data-field-name'); + markdownEditors.forEach(function (markdownEditor) { + var fieldName = markdownEditor.getAttribute('data-field-name'); - var previewTabSelector = '#' + fieldName + '-preview-tab'; - var targetSelector = '#' + fieldName + '-markdown-target'; - var sourceSelector = markdownEditor.querySelector('.markdown-source'); + var previewTabSelector = '#' + fieldName + '-preview-tab'; + var targetSelector = '#' + fieldName + '-markdown-target'; + var sourceSelector = markdownEditor.querySelector('.markdown-source'); - var previewTabEl = markdownEditor.querySelector(previewTabSelector); - var targetEl = markdownEditor.querySelector(targetSelector); + var previewTabEl = markdownEditor.querySelector(previewTabSelector); + var targetEl = markdownEditor.querySelector(targetSelector); - var reader = new commonmark.Parser({safe: true}); - var writer = new commonmark.HtmlRenderer({safe: true, softbreak: '
'}); + previewTabEl.addEventListener('click', function () { + var rendered = markdown.render(sourceSelector.value.trim()); + targetEl.innerHTML = rendered; + }); + }); +}); - previewTabEl.addEventListener('click', function () { - var parsed = reader.parse(sourceSelector.value.trim()); - targetEl.innerHTML = writer.render(parsed); - }); - }); +// Render markdown from elements with "markdown-text" attribute +document.addEventListener("DOMContentLoaded", function() { + + var markdownTargets = document.querySelectorAll('[markdown-text]'); + for (var target of markdownTargets) { + var rendered = markdown.render(target.innerHTML); + target.innerHTML = rendered; + } }); // diff --git a/nyaa/templates/_formhelpers.html b/nyaa/templates/_formhelpers.html index 02fb743..d467735 100644 --- a/nyaa/templates/_formhelpers.html +++ b/nyaa/templates/_formhelpers.html @@ -35,6 +35,7 @@ {% endif %}
{{ field.label(class='control-label') }} + Markdown supported
- {{ render_field(field, False, class_='form-control markdown-source') }} + {# Render this field manually, because we need to escape the inner text #} + + {% if field.errors %} +
+ {% if field.errors|length < 2 %} + {% for error in field.errors %} + {{ error }} + {% endfor %} + {% else %} +
    + {% for error in field.errors %} +
  • {{ error }}
  • + {% endfor %} +
+ {% endif %} +
+ {% endif %}
diff --git a/nyaa/templates/edit.html b/nyaa/templates/edit.html index 07fc734..afc3df1 100644 --- a/nyaa/templates/edit.html +++ b/nyaa/templates/edit.html @@ -89,7 +89,7 @@
- +
diff --git a/nyaa/templates/help.html b/nyaa/templates/help.html index c8b4b81..64582fb 100644 --- a/nyaa/templates/help.html +++ b/nyaa/templates/help.html @@ -2,7 +2,64 @@ {% block title %}Help :: {{ config.SITE_NAME }}{% endblock %} {% block body %} -

Coming soon (tm)

+{% macro linkable_header(heading, label) %} +

{{ heading }}

+{% endmacro %} + +

Help

+ +

Using the Site

+ +{{ linkable_header("How to Download", "how-to-dl") }} +

+ This site only offers torrent files and magnet links. To download the content of + the torrents, you will have to use a BitTorrent client such as qBitTorrent, + µTorrent, Transmission or Deluge. +

+ +{{ linkable_header("Using the Search Function", "using-search") }} +

+ You can combine search terms with the | operator, such as + horrible|cartel. +

+

+ To exclude results matching a certain word, prefix them with -, + e.g. FFF -memesubs, which will return torrents with FFF in the + name, but not those which have memesubs in the name as well. +

+

+ If you want to search for a several-word expression in its entirety, you can + surround searches with " (double quotes), such as + "foo bar", which would match torrents named foo bar but not + those named bar foo. +

+ +{{ linkable_header("Reporting Torrents", "reporting") }} +

+ If you find a torrent that breaks the rules, click the + button to the right + of the torrent's information page. Then, enter a reason for your report in the + dialog that opens, and hit the button to confirm. +

+ +{{ linkable_header("Styling Descriptions and Comments", "styling") }} +

+ You can style your comments and your torrent's description using + Markdown + . This includes adding images or linking to external websites. +

+

+ To link to an external site, use [label of link](https://example.com) + where the text in the [] square brackets is the shown text of your + link, and the URL in the () parentheses is the URL your link will + point to. +

+

+ Embedding an image is similar. Use ![alt text](https://example.com/image.jpg) + to have an image embedded in your comment or description. Note the ! + exclamation mark at the beginning, denoting that this link is an image. +

{#

Help

The search engine is located at the top right, and it allows users to search through the torrent titles available on the site. Results matching either word A or B can be included by typing a vertical bar between them (|). Results matching a certain word can be excluded by prefixing that word with a hyphen-minus (-). Phrases can be matched by surrounding them with double-quotes (). Search results can be filtered by category, remake, trusted, and/or A+ status, and then narrowed down further by age and size ranges as well as excluding specific users. Sorting can be done in ascending or descending order by date, amount of seeders/leechers/downloads, size, or name. The search engine adapts to the current view and makes it possible to search for specific torrents in a specific subcategory from a specific user.

diff --git a/nyaa/templates/layout.html b/nyaa/templates/layout.html index ffbb18f..ce82404 100644 --- a/nyaa/templates/layout.html +++ b/nyaa/templates/layout.html @@ -43,7 +43,7 @@ - + diff --git a/nyaa/templates/view.html b/nyaa/templates/view.html index 82e12cc..3822125 100644 --- a/nyaa/templates/view.html +++ b/nyaa/templates/view.html @@ -81,13 +81,13 @@
-
- {% if torrent.description %} +
+ {%- if torrent.description -%} {# Escape newlines into html entities because CF strips blank newlines #} - {{ torrent.description | escape | replace('\r\n', '\n') | replace('\n', ' '|safe) }} - {% else %} + {{- torrent.description | escape | replace('\r\n', '\n') | replace('\n', ' '|safe) -}} + {%- else -%} #### No description. - {% endif%} + {%- endif -%}
@@ -161,19 +161,12 @@
{# Escape newlines into html entities because CF strips blank newlines #} -
{{ comment.text }}
+
{{ comment.text }}
- + {% endfor %} {% if comment_form %} @@ -207,7 +200,7 @@ -