Skip to content

Commit

Permalink
🐎 Improve performance of large files
Browse files Browse the repository at this point in the history
  • Loading branch information
tterb committed Nov 14, 2017
1 parent 2016bd3 commit 30a13ff
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 37 deletions.
72 changes: 37 additions & 35 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ const packageJSON = require(path.join(__dirname, '/package.json'));
const emoji = require('node-emoji');
const Color = require('color');
const os = require('os');
const highlight = require('showdown-highlight');
//conse marked = require('marked');
// const highlight = require('showdown-highlight');
require('showdown-youtube');

getUserSettings();
let currentTheme = settings.get('editorTheme');
let conf = {
mode: 'yaml-frontmatter',
base: 'gfm',
viewportMargin: 100000000000,
viewportMargin: 10,
tabSize: 2,
lineWrapping: true,
lineNumbers: settings.get('lineNumbers'),
Expand Down Expand Up @@ -112,7 +113,7 @@ let converter = new showdown.Converter({
simplifiedAutoLink: false,
excludeTrailingPunctuationFromURLs: true,
disableForced4SpacesIndentedSublists: true,
extensions: ['youtube', highlight]
extensions: ['youtube']
});

window.onload = () => {
Expand Down Expand Up @@ -168,7 +169,7 @@ window.onload = () => {
$(this).children('ul').hide();
});

$('#table-button').on('click', () => {
$('.table-button').on('click', () => {
$('#table-modal').modal();
createTable($('#columns').val(),$('#rows').val(),$('.on').attr('id').slice(0,-5));
});
Expand Down Expand Up @@ -344,38 +345,39 @@ function openInBrowser(url) {

function renderMarkdown(cm) {
let markdownText = cm.getValue();
// Remove the YAML frontmatter
if(settings.get('hideYAMLFrontMatter'))
markdownText = removeYAMLPreview(markdownText);
// Convert emoji's
markdownText = emoji.emojify(markdownText, (name) => { return name; }, formatEmoji);
var renderedMD = converter.makeHtml(markdownText);
// Render LaTex
let texConfig = [['$$', '\$\$', false], ['$$ ', ' \$\$', true]];
if(settings.get('mathRendering'))
renderedMD = katex.renderLaTeX(renderedMD, texConfig);
// Markdown -> Preview
$('#mdPreview').html(renderedMD);
// Allows for making '<br>' tags more GitHub-esque
$('#mdPreview p').each(function() {
if($(this).html() === '<br>') {
$(this).attr('class', 'break');
}
});
// Markdown -> HTML
converter.setOption('noHeaderId', true);
$('#htmlPreview').val(converter.makeHtml(markdownText));
// Handle preview checkboxes
$('#mdPreview :checkbox').removeAttr('disabled');
$('#mdPreview :checkbox').on('click', function() {
event.preventDefault();
});
if(this.isFileLoadedInitially) {
this.setClean();
this.isFileLoadedInitially = false;
sendIPC('has-changes');
// Remove the YAML frontmatter
if(settings.get('hideYAMLFrontMatter'))
markdownText = removeYAMLPreview(markdownText);
// Convert emoji's
markdownText = emoji.emojify(markdownText, (name) => { return name; }, formatEmoji);
var renderedMD = converter.makeHtml(markdownText);
// Render LaTex
let texConfig = [['$$', '\$\$', false], ['$$ ', ' \$\$', true]];
if(settings.get('mathRendering'))
renderedMD = katex.renderLaTeX(renderedMD, texConfig);
// Markdown -> Preview
$('#mdPreview').html(renderedMD);
// Allows for making '<br>' tags more GitHub-esque
$('#mdPreview p').each(function() {
if($(this).html() === '<br>') {
$(this).attr('class', 'break');
}
this.updateWindowTitle(this.currentFile);
countWords();
});
// Markdown -> HTML
converter.setOption('noHeaderId', true);
$('#htmlPreview').val(converter.makeHtml(markdownText));
// Handle preview checkboxes
$('#mdPreview :checkbox').removeAttr('disabled');
$('#mdPreview :checkbox').on('click', function() {
event.preventDefault();
});
if(this.isFileLoadedInitially) {
this.setClean();
this.isFileLoadedInitially = false;
}
this.updateWindowTitle(this.currentFile);
countWords();
}

var formatEmoji = (code, name) => {
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"codemirror-spell-checker": "^1.1.2",
"color": "^2.0.0",
"devtron": "^1.4.0",
"electron": "1.7.8",
"electron": "^1.7.8",
"electron-command-palette": "^0.1.1",
"electron-config": "^1.0.0",
"electron-json-storage": "latest",
Expand All @@ -94,7 +94,6 @@
"node-emoji": "^1.8.1",
"parse-filepath": "1.0.1",
"showdown": "^1.8.1",
"showdown-highlight": "^1.0.2",
"showdown-youtube": "^1.2.1",
"yargs": "^9.0.1"
}
Expand Down

0 comments on commit 30a13ff

Please sign in to comment.