diff --git a/judge/jinja2/markdown/__init__.py b/judge/jinja2/markdown/__init__.py index bf9c99a..b91679c 100644 --- a/judge/jinja2/markdown/__init__.py +++ b/judge/jinja2/markdown/__init__.py @@ -12,11 +12,6 @@ from lxml.etree import ParserError, XMLSyntaxError from judge.highlight_code import highlight_code from judge.jinja2.markdown.lazy_load import lazy_load as lazy_load_processor from judge.jinja2.markdown.math import MathInlineGrammar, MathInlineLexer, MathRenderer -from judge.jinja2.markdown.spoiler import ( - SpoilerInlineGrammar, - SpoilerInlineLexer, - SpoilerRenderer, -) from judge.utils.camo import client as camo_client from judge.utils.texoid import TEXOID_ENABLED, TexoidRenderer from .. import registry @@ -25,23 +20,22 @@ logger = logging.getLogger("judge.html") NOFOLLOW_WHITELIST = settings.NOFOLLOW_EXCLUDED - class CodeSafeInlineGrammar(mistune.InlineGrammar): double_emphasis = re.compile(r"^\*{2}([\s\S]+?)()\*{2}(?!\*)") # **word** emphasis = re.compile(r"^\*((?:\*\*|[^\*])+?)()\*(?!\*)") # *word* class AwesomeInlineGrammar( - MathInlineGrammar, SpoilerInlineGrammar, CodeSafeInlineGrammar + MathInlineGrammar, CodeSafeInlineGrammar ): pass -class AwesomeInlineLexer(MathInlineLexer, SpoilerInlineLexer, mistune.InlineLexer): +class AwesomeInlineLexer(MathInlineLexer, mistune.InlineLexer): grammar_class = AwesomeInlineGrammar -class AwesomeRenderer(MathRenderer, SpoilerRenderer, mistune.Renderer): +class AwesomeRenderer(MathRenderer, mistune.Renderer): def __init__(self, *args, **kwargs): self.nofollow = kwargs.pop("nofollow", True) self.texoid = TexoidRenderer() if kwargs.pop("texoid", False) else None @@ -129,14 +123,28 @@ class AwesomeRenderer(MathRenderer, SpoilerRenderer, mistune.Renderer): return super(AwesomeRenderer, self).header(text, level + 2, *args, **kwargs) +def create_spoiler(value, style): + respoiler = re.compile(r"(^\|\|(.+)\s+([\s\S]+?)\s*\|\|)", re.MULTILINE) + matches = re.findall(respoiler, value) + html = "
" \ + + "{summary}" \ + + "{detail}
" + + for entire, summary, detail in matches: + detail = markdown(detail, style) + new_html = html.format(summary=summary, detail=detail) + value = value.replace(entire, new_html) + return value + @registry.filter -def markdown(value, style, math_engine=None, lazy_load=False): +def markdown(value, style, math_engine=None, lazy_load=False, hard_wrap=False): styles = settings.MARKDOWN_STYLES.get(style, settings.MARKDOWN_DEFAULT_STYLE) escape = styles.get("safe_mode", True) nofollow = styles.get("nofollow", True) texoid = TEXOID_ENABLED and styles.get("texoid", False) math = hasattr(settings, "MATHOID_URL") and styles.get("math", False) + value = create_spoiler(value, style) post_processors = [] if styles.get("use_camo", False) and camo_client is not None: post_processors.append(camo_client.update_tree) @@ -155,7 +163,7 @@ def markdown(value, style, math_engine=None, lazy_load=False): inline=AwesomeInlineLexer, parse_block_html=1, parse_inline_html=1, - hard_wrap=True, + hard_wrap=hard_wrap, ) result = markdown(value) if post_processors: diff --git a/judge/jinja2/markdown/math.py b/judge/jinja2/markdown/math.py index 8063ab6..dcde0d1 100644 --- a/judge/jinja2/markdown/math.py +++ b/judge/jinja2/markdown/math.py @@ -11,8 +11,8 @@ mistune._pre_tags.append("latex") class MathInlineGrammar(mistune.InlineGrammar): block_math = re.compile(r"^\$\$(.*?)\$\$|^\\\[(.*?)\\\]", re.DOTALL) - math = re.compile(r"^~(.*?)~|\$(.*?)\$|^\\\((.*?)\\\)", re.DOTALL) - text = re.compile(r"^[\s\S]+?(?=[\\ - - %s - -
%s
- """ % ( - summary, - text, - ) diff --git a/resources/content-description.scss b/resources/content-description.scss index d2ff6f5..859056d 100644 --- a/resources/content-description.scss +++ b/resources/content-description.scss @@ -293,11 +293,4 @@ a.view-pdf { } details summary { cursor: pointer; -} -details[open] p { - background: #def; - padding: 0.3em !important; - border: 1px solid grey; - border-radius: 4px; - margin-top: 0 !important; } \ No newline at end of file diff --git a/resources/mathjax_config.js b/resources/mathjax_config.js index a4e7570..5186348 100644 --- a/resources/mathjax_config.js +++ b/resources/mathjax_config.js @@ -3,6 +3,7 @@ window.MathJax = { tex2jax: { inlineMath: [ ['~', '~'], + ['$', '$'], ['\\(', '\\)'] ] }, diff --git a/templates/chat/chat.html b/templates/chat/chat.html index 155efa3..1f155a6 100644 --- a/templates/chat/chat.html +++ b/templates/chat/chat.html @@ -190,7 +190,7 @@ let META_HEADER = [ } function check_new_message(message, tmp_id, room) { - if (room == "{{room}}") { + if (room == room_id) { $.get({ url: "{{ url('chat_message_ajax') }}", data: { diff --git a/templates/chat/message.html b/templates/chat/message.html index cd706a5..15ed977 100644 --- a/templates/chat/message.html +++ b/templates/chat/message.html @@ -21,7 +21,7 @@ {% endif %}
- {{message.body | markdown('comment', MATH_ENGINE)|reference|str|safe }} + {{message.body | markdown('comment', MATH_ENGINE, hard_wrap=True)|reference|str|safe }}