Skip to content

Commit

Permalink
dependencies: Upgrade to-markdown 3.1.1 to turndown 5.0.3.
Browse files Browse the repository at this point in the history
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
  • Loading branch information
andersk authored and timabbott committed Nov 12, 2019
1 parent cce85f6 commit fffef41
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 193 deletions.
1 change: 0 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@
"templates": false,
"tictactoe_widget": false,
"timerender": false,
"toMarkdown": false,
"todo_widget": false,
"top_left_corner": false,
"topic_data": false,
Expand Down
5 changes: 2 additions & 3 deletions frontend_tests/node_tests/copy_and_paste.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"stacktrace-gps": "^3.0.3",
"style-loader": "^1.0.0",
"terser-webpack-plugin": "^2.1.0",
"to-markdown": "^3.1.0",
"turndown": "^5.0.3",
"underscore": "^1.9.1",
"webfonts-loader": "^5.0.0",
"webpack": "^4.33.0",
Expand Down
1 change: 0 additions & 1 deletion static/js/bundles/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import "blueimp-md5/js/md5.js";
import "clipboard/dist/clipboard.js";
import "winchan/winchan.js";
import "handlebars/dist/cjs/handlebars.runtime.js";
import "to-markdown/dist/to-markdown.js";
import "flatpickr/dist/flatpickr.js";
import "flatpickr/dist/plugins/confirmDate/confirmDate.js";
import "sortablejs/Sortable.js";
Expand Down
79 changes: 32 additions & 47 deletions static/js/copy_and_paste.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const TurndownService = require("turndown/lib/turndown.cjs.js");

function find_boundary_tr(initial_tr, iterate_row) {
var j;
var skip_same_td_check = false;
Expand Down Expand Up @@ -259,53 +261,36 @@ exports.analyze_selection = function (selection) {
};

exports.paste_handler_converter = function (paste_html) {
var converters = {
converters: [
{
filter: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'],
replacement: function (content) {
return content;
},
},

{
filter: ['em', 'i'],
replacement: function (content) {
return '*' + content + '*';
},
},
{
// Checks for raw links without custom text or title.
filter: function (node) {
return node.nodeName === "A" &&
node.href === node.innerHTML &&
node.href === node.title;
},
replacement: function (content) {
return content;
},
},
{
// Checks for escaped ordered list syntax.
filter: function (node) {
return /(\d+)\\\. /.test(node.innerHTML);
},
replacement: function (content) {
return content.replace(/(\d+)\\\. /g, '$1. ');
},
},
],
};
var markdown_html = toMarkdown(paste_html, converters);

// Now that we've done the main conversion, we want to remove
// any HTML tags that weren't converted to markdown-style
// text, since Bugdown doesn't support those.
var div = document.createElement("div");
div.innerHTML = markdown_html;
// Using textContent for modern browsers, innerText works for Internet Explorer
var markdown_text = div.textContent || div.innerText || "";
markdown_text = markdown_text.trim();
const turndownService = new TurndownService();
turndownService.addRule('headings', {
filter: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'],
replacement: function (content) {
return content;
},
});
turndownService.addRule('emphasis', {
filter: ['em', 'i'],
replacement: function (content) {
return '*' + content + '*';
},
});
// Checks for raw links without custom text or title.
turndownService.addRule('links', {
filter: function (node) {
return node.nodeName === "A" &&
node.href === node.innerHTML &&
node.href === node.title;
},
replacement: function (content) {
return content;
},
});

let markdown_text = turndownService.turndown(paste_html);

// Checks for escaped ordered list syntax.
markdown_text = markdown_text.replace(/^(\W* {0,3})(\d+)\\\. /gm, '$1$2. ');

// Removes newlines before the start of a list and between list elements.
markdown_text = markdown_text.replace(/\n+([*+-])/g, '\n$1');
return markdown_text;
Expand Down
1 change: 0 additions & 1 deletion tools/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ export default (env?: string): webpack.Configuration[] => {
{ path: "jquery/dist/jquery.js", name: ['$', 'jQuery'] },
{ path: "underscore/underscore.js", name: '_' },
{ path: "handlebars/dist/cjs/handlebars.runtime.js", name: 'Handlebars' },
{ path: "to-markdown/dist/to-markdown.js", name: 'toMarkdown' },
{ path: "sortablejs/Sortable.js"},
{ path: "winchan/winchan.js", name: 'WinChan'},
];
Expand Down
2 changes: 1 addition & 1 deletion version.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
# historical commits sharing the same major version, in which case a
# minor version bump suffices.

PROVISION_VERSION = '64.0'
PROVISION_VERSION = '65.0'

0 comments on commit fffef41

Please sign in to comment.