Add partial citeblock and real links
This commit is contained in:
parent
5f89baf449
commit
317fc07a45
@ -13,7 +13,7 @@ from amanuensis.config import prepend, json_rw, json_ro, logger
|
||||
from amanuensis.config.loader import AttrOrderedDict
|
||||
from amanuensis.errors import ArgumentError
|
||||
from amanuensis.lexicon import LexiconModel
|
||||
from amanuensis.parser import parse_raw_markdown, GetCitations, HtmlRenderer, filesafe_title
|
||||
from amanuensis.parser import parse_raw_markdown, GetCitations, HtmlRenderer, filesafe_title, titlesort
|
||||
from amanuensis.resources import get_stream
|
||||
|
||||
def valid_name(name):
|
||||
@ -300,7 +300,7 @@ def publish_turn(lexicon, drafts):
|
||||
# Get all citations
|
||||
citations_by_title = {}
|
||||
for title, article in article_renderable_by_title.items():
|
||||
citations_by_title[title] = article.render(GetCitations())
|
||||
citations_by_title[title] = sorted(set(article.render(GetCitations())), key=titlesort)
|
||||
|
||||
# Get the written and phantom lists from the citation map
|
||||
written_titles = list(citations_by_title.keys())
|
||||
@ -327,7 +327,7 @@ def publish_turn(lexicon, drafts):
|
||||
# Render article HTML and save to article cache
|
||||
rendered_html_by_title = {}
|
||||
for title, article in article_renderable_by_title.items():
|
||||
html = article.render(HtmlRenderer(written_titles))
|
||||
html = article.render(HtmlRenderer(lexicon.name, written_titles))
|
||||
filename = filesafe_title(title)
|
||||
with lexicon.ctx.article.edit(filename, create=True) as f:
|
||||
f['title'] = title
|
||||
|
@ -3,12 +3,17 @@ Internal module encapsulating visitors that render articles into
|
||||
readable formats.
|
||||
"""
|
||||
|
||||
from flask import url_for
|
||||
|
||||
from amanuensis.parser.helpers import filesafe_title
|
||||
|
||||
|
||||
class HtmlRenderer():
|
||||
"""
|
||||
Renders an article token tree into published article HTML.
|
||||
"""
|
||||
def __init__(self, written_articles):
|
||||
def __init__(self, lexicon_name, written_articles):
|
||||
self.lexicon_name = lexicon_name
|
||||
self.written_articles = written_articles
|
||||
|
||||
def TextSpan(self, span):
|
||||
@ -41,7 +46,12 @@ class HtmlRenderer():
|
||||
link_class = ''
|
||||
else:
|
||||
link_class = ' class="phantom"'
|
||||
return f'<a href="#"{link_class}>{"".join(span.recurse(self))}</a>'
|
||||
# link = url_for(
|
||||
# 'lexicon.article',
|
||||
# name=self.lexicon_name,
|
||||
# title=filesafe_title(span.cite_target))
|
||||
link = f'/lexicon/{self.lexicon_name}/article/{filesafe_title(span.cite_target)}'
|
||||
return f'<a href="{link}"{link_class}>{"".join(span.recurse(self))}</a>'
|
||||
|
||||
|
||||
|
||||
|
@ -8,6 +8,7 @@ from flask_login import current_user
|
||||
|
||||
# Module imports
|
||||
from amanuensis.lexicon import LexiconModel
|
||||
from amanuensis.parser import filesafe_title
|
||||
from amanuensis.user import UserModel
|
||||
|
||||
|
||||
@ -27,6 +28,10 @@ def register_custom_filters(app):
|
||||
dt = datetime.fromtimestamp(ts)
|
||||
return dt.strftime(formatstr)
|
||||
|
||||
@app.template_filter("articlelink")
|
||||
def article_link(title):
|
||||
return url_for('lexicon.article', name=g.lexicon.name, title=filesafe_title(title))
|
||||
|
||||
|
||||
def lexicon_param(route):
|
||||
"""Wrapper for loading a route's lexicon"""
|
||||
|
@ -71,7 +71,9 @@ def get_bp():
|
||||
with g.lexicon.ctx.article.read(title) as a:
|
||||
article = dict(a)
|
||||
article['html'] = Markup(a['html'] or "")
|
||||
return render_template('lexicon/article.html', article=article)
|
||||
with g.lexicon.ctx.read('info') as info:
|
||||
cites = info[a.title]['citations']
|
||||
return render_template('lexicon/article.html', article=article, cites=cites)
|
||||
|
||||
@bp.route('/rules/', methods=['GET'])
|
||||
@lexicon_param
|
||||
@ -183,8 +185,12 @@ def get_bp():
|
||||
return redirect(url_for('lexicon.session', name=name))
|
||||
|
||||
parsed_draft = parse_raw_markdown(draft.contents)
|
||||
rendered_html = parsed_draft.render(PreviewHtmlRenderer(
|
||||
{'Article':'default','Phantom':None}))
|
||||
with g.lexicon.ctx.read('info') as info:
|
||||
authorship = {
|
||||
title: article.character
|
||||
for title, article in info.items()
|
||||
}
|
||||
rendered_html = parsed_draft.render(PreviewHtmlRenderer(authorship))
|
||||
|
||||
# If the article is ready and awaiting review
|
||||
if not draft.status.approved:
|
||||
|
@ -8,8 +8,14 @@
|
||||
{% endfor %}
|
||||
|
||||
<h1>{{ article.title }}</h1>
|
||||
|
||||
{{ article.html }}
|
||||
|
||||
{% endblock %}
|
||||
{% set template_content_blocks = [self.main()] %}
|
||||
|
||||
{% block citations %}
|
||||
{% for cite in cites %}
|
||||
<a href="{{ cite|articlelink }}">{{ cite }}</a> /
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
|
||||
{% set template_content_blocks = [self.main(), self.citations()] %}
|
Loading…
Reference in New Issue
Block a user