diff --git a/frappe/__init__.py b/frappe/__init__.py index fb9076e618..ad940cf91c 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -434,8 +434,7 @@ def sendmail(recipients=[], sender="", subject="No Subject", message="No Message message = content or message if as_markdown: - from markdown2 import markdown - message = markdown(message) + message = frappe.utils.md_to_html(message) if not delayed: now = True diff --git a/frappe/email/doctype/notification/notification.py b/frappe/email/doctype/notification/notification.py index f48c20628a..66c1642d65 100644 --- a/frappe/email/doctype/notification/notification.py +++ b/frappe/email/doctype/notification/notification.py @@ -11,7 +11,6 @@ from frappe.core.doctype.role.role import get_emails_from_role from frappe.utils import validate_email_add, nowdate, parse_val, is_html from frappe.utils.jinja import validate_template from frappe.modules.utils import export_module_json, get_doc_module -from markdown2 import markdown from six import string_types from frappe.integrations.doctype.slack_webhook_url.slack_webhook_url import send_slack_message @@ -225,7 +224,7 @@ def get_context(context): self.message = self.get_template() if not is_html(self.message): - self.message = markdown(self.message) + self.message = frappe.utils.md_to_html(self.message) @frappe.whitelist() def get_documents_for_today(notification): diff --git a/frappe/utils/__init__.py b/frappe/utils/__init__.py index c2cb15e56a..d12726870c 100644 --- a/frappe/utils/__init__.py +++ b/frappe/utils/__init__.py @@ -6,7 +6,6 @@ from __future__ import unicode_literals, print_function from werkzeug.test import Client import os, re, sys, json, hashlib, requests, traceback -from markdown2 import markdown as _markdown from .html_utils import sanitize_html import frappe from frappe.utils.identicon import Identicon @@ -442,7 +441,7 @@ def watch(path, handler=None, debug=True): observer.join() def markdown(text, sanitize=True, linkify=True): - html = _markdown(text) + html = frappe.utils.md_to_html(text) if sanitize: html = html.replace("", "") diff --git a/frappe/utils/data.py b/frappe/utils/data.py index 6cd6dbec0b..3cff6d18e0 100644 --- a/frappe/utils/data.py +++ b/frappe/utils/data.py @@ -938,10 +938,20 @@ def to_markdown(html): return text -def to_html(markdown_text): +def md_to_html(markdown_text): + extras = { + 'fenced-code-blocks': None, + 'tables': None, + 'header-ids': None, + 'highlightjs-lang': None, + 'html-classes': { + 'table': 'table table-bordered' + } + } + html = None try: - html = markdown(markdown_text) + html = markdown(markdown_text, extras=extras) except MarkdownError: pass diff --git a/frappe/utils/help.py b/frappe/utils/help.py index 4fc4692a0b..cd3972e483 100644 --- a/frappe/utils/help.py +++ b/frappe/utils/help.py @@ -10,7 +10,6 @@ from frappe.model.db_schema import DbManager from frappe.installer import get_root_connection from frappe.database import Database import os, subprocess -from markdown2 import markdown from bs4 import BeautifulSoup import jinja2.exceptions @@ -182,7 +181,7 @@ class HelpDatabase(object): relpath = self.get_out_path(fpath) relpath = relpath.replace("user", app) - content = markdown(content) + content = frappe.utils.md_to_html(content) title = self.make_title(basepath, fname, content) intro = self.make_intro(content) content = self.make_content(content, fpath, relpath, app) diff --git a/frappe/website/js/syntax_highlight.js b/frappe/website/js/syntax_highlight.js new file mode 100644 index 0000000000..199174b1e5 --- /dev/null +++ b/frappe/website/js/syntax_highlight.js @@ -0,0 +1,18 @@ +const hljs = require('highlight.js/lib/highlight'); + +hljs.registerLanguage('javascript', require('highlight.js/lib/languages/javascript')); +hljs.registerLanguage('python', require('highlight.js/lib/languages/python')); +hljs.registerLanguage('xml', require('highlight.js/lib/languages/xml')); +hljs.registerLanguage('django', require('highlight.js/lib/languages/django')); +hljs.registerLanguage('bash', require('highlight.js/lib/languages/bash')); +hljs.registerLanguage('css', require('highlight.js/lib/languages/css')); +hljs.registerLanguage('markdown', require('highlight.js/lib/languages/markdown')); +hljs.registerLanguage('diff', require('highlight.js/lib/languages/diff')); +hljs.registerLanguage('json', require('highlight.js/lib/languages/json')); +hljs.registerLanguage('less', require('highlight.js/lib/languages/less')); +hljs.registerLanguage('nginx', require('highlight.js/lib/languages/nginx')); +hljs.registerLanguage('scss', require('highlight.js/lib/languages/scss')); +hljs.registerLanguage('shell', require('highlight.js/lib/languages/shell')); +hljs.registerLanguage('sql', require('highlight.js/lib/languages/sql')); + +module.exports = hljs; diff --git a/frappe/website/js/website.js b/frappe/website/js/website.js index 7937795e7d..5744ebd977 100644 --- a/frappe/website/js/website.js +++ b/frappe/website/js/website.js @@ -2,7 +2,7 @@ // MIT License. See license.txt /* eslint-disable no-console */ -import hljs from 'highlight.js'; +import hljs from './syntax_highlight'; frappe.provide("website"); frappe.provide("frappe.awesome_bar_path"); @@ -265,9 +265,7 @@ $.extend(frappe, { }, highlight_code_blocks: function() { - $('pre code').each(function(i, block) { - hljs.highlightBlock(block); - }); + hljs.initHighlighting(); }, bind_filters: function() { // set in select diff --git a/frappe/website/router.py b/frappe/website/router.py index 233942116e..e9ab0a5269 100644 --- a/frappe/website/router.py +++ b/frappe/website/router.py @@ -223,13 +223,12 @@ def get_page_info(path, app, start, basepath=None, app_path=None, fname=None): def setup_source(page_info): '''Get the HTML source of the template''' - from markdown2 import markdown jenv = frappe.get_jenv() source = jenv.loader.get_source(jenv, page_info.template)[0] html = '' if page_info.template.endswith('.md'): - source = markdown(source, extras=["fenced-code-blocks"]) + source = frappe.utils.md_to_html(source) if not page_info.show_sidebar: source = '