feat: source_format selector on new-thread create form
The preview fix (64a15b6) honored source_format only when the textarea
already declared one — which works for editing an existing node but
not for creating a new one. Authors writing RST in the create form
saw their preview rendered as markdown, then saved into a node whose
source_format defaulted to markdown — so even the final saved page
came back wrong.
Three pieces:
- create.j2: <select> for source_format alongside the textarea.
Default markdown; rst, html, mediawiki, latex, org, asciidoc,
textile available. onchange syncs the chosen value into
textarea.dataset.sourceFormat and re-runs preview, so the
existing custom.js sendPreview picks it up unchanged.
- new_thread.py: read source_format from request.params, pass to
set_data() so the created node's persistent source_format matches
what the author saw in preview.
- No JS change needed — custom.js already reads
textarea.dataset.sourceFormat.
This commit is contained in:
parent
5942f6b2b3
commit
d1145510e2
2 changed files with 16 additions and 1 deletions
|
|
@ -11,10 +11,24 @@
|
|||
name = "thread_data"
|
||||
id = "thread_data_textarea"
|
||||
class = "common-textarea"
|
||||
data-source-format = "markdown"
|
||||
onkeyup = "previewAjax( 'thread_data_textarea', 'preview', show_raw=true, mathjax={{ request.mathjax }} )"
|
||||
placeholder = "What do you want to say? markdown"
|
||||
required></textarea>
|
||||
|
||||
<label for="source_format_select" style="display:inline-block;margin-right:0.5em">format:</label>
|
||||
<select id="source_format_select" name="source_format"
|
||||
onchange="document.getElementById('thread_data_textarea').dataset.sourceFormat = this.value; previewAjax('thread_data_textarea', 'preview', show_raw=true, mathjax={{ request.mathjax }})">
|
||||
<option value="markdown" selected>markdown</option>
|
||||
<option value="rst">reStructuredText</option>
|
||||
<option value="html">html</option>
|
||||
<option value="mediawiki">mediawiki</option>
|
||||
<option value="latex">latex</option>
|
||||
<option value="org">org</option>
|
||||
<option value="asciidoc">asciidoc</option>
|
||||
<option value="textile">textile</option>
|
||||
</select>
|
||||
|
||||
<div id='preview' name='preview' class="preview"></div>
|
||||
|
||||
{% include 'csrf.j2' %}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ def new_thread(request):
|
|||
thread_title = request.params.get("thread_title", "")
|
||||
thread_data = request.params.get("thread_data", "")
|
||||
anonymous_name = request.params.get("anonymous_name", "").strip()
|
||||
source_format = request.params.get("source_format", "").strip() or None
|
||||
|
||||
if request.spam:
|
||||
return request.spam
|
||||
|
|
@ -61,7 +62,7 @@ def new_thread(request):
|
|||
node.namespace = request.namespace
|
||||
node.ip_address = unicode(request.client_addr)
|
||||
node.title = thread_title
|
||||
node.set_data(thread_data, dbsession=request.dbsession)
|
||||
node.set_data(thread_data, dbsession=request.dbsession, source_format=source_format)
|
||||
|
||||
# Handle anonymous vs authenticated user
|
||||
if user_surrogate:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue