Skip to content

Commit

Permalink
Enables syntax highlighting and preserves theme in "render selection …
Browse files Browse the repository at this point in the history
…mode" #26
  • Loading branch information
ggrossetie committed Feb 9, 2014
1 parent f456490 commit ab34c43
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 41 deletions.
6 changes: 1 addition & 5 deletions html/inject.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
<html>
<head>
<link rel="stylesheet" id="github-highlight-style" href="../css/github.min.css">

<script type="text/javascript" src="../js/opal.js"></script>
<script type="text/javascript" src="../js/asciidoctor.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/highlight.min.js"></script>
<script type="text/javascript" src="../js/renderer.js"></script>

<link rel="stylesheet" id="asciidoctor-style" href="../css/themes/asciidoctor.css">
<link rel="stylesheet" id="font-awesome-style" href="../css/font-awesome.min.css">
</head>
<div id="content">
</div>
Expand Down
35 changes: 0 additions & 35 deletions js/asciidocify.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
var autoReloadInterval;
var AUTO_RELOAD_INTERVAL_TIME = 2000;
var ENABLE_RENDER_KEY = 'ENABLE_RENDER';
var THEME_KEY = 'THEME';

/**
* AsciiDocify the content!
Expand Down Expand Up @@ -89,40 +88,6 @@
return contentType && (contentType.indexOf('html') > -1);
}

/**
* Append highlight.js script
*/
function appendHighlightJsScript() {
var highlightJsScript = document.createElement('script');
highlightJsScript.type = 'text/javascript';
highlightJsScript.src = chrome.extension.getURL('js/highlight.min.js');
document.head.appendChild(highlightJsScript);
}

/**
* Append css files
*/
function appendStyles() {
chrome.storage.local.get(THEME_KEY, function (items) {
var theme = items[THEME_KEY];
if (!theme) {
// Default theme
theme = 'asciidoctor';
}
var themeLink = document.createElement('link');
themeLink.rel = 'stylesheet';
themeLink.id = 'asciidoctor-style';
themeLink.href = chrome.extension.getURL('css/themes/' + theme + '.css');
document.head.appendChild(themeLink);

});
var githubHighlightLink = document.createElement('link');
githubHighlightLink.rel = 'stylesheet';
githubHighlightLink.id = 'github-highlight-style';
githubHighlightLink.href = chrome.extension.getURL('css/github.min.css');
document.head.appendChild(githubHighlightLink);
}

asciidocify();

}(document));
1 change: 1 addition & 0 deletions js/inject.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var alreadyRun = false;
function inject(data){
if (!alreadyRun) {
appendStyles();
render(data);
alreadyRun = true;
}
Expand Down
36 changes: 35 additions & 1 deletion js/renderer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var CUSTOM_ATTRIBUTES_KEY = 'CUSTOM_ATTRIBUTES';
var LIVERELOADJS_DETECTED_KEY = 'LIVERELOADJS_DETECTED';
var LIVERELOADJS_FILENAME = 'livereload.js';
var THEME_KEY = 'THEME';

/**
* Render AsciiDoc content as HTML
Expand All @@ -18,7 +19,6 @@ var render = function (data) {
appendFontAwesomeStyle();
}
generatedHtml = asciidoctorDocument.$render();
console.log('generatedHtml ' + generatedHtml);
}
catch (e) {
showErrorMessage(e.name + ' : ' + e.message);
Expand Down Expand Up @@ -96,6 +96,40 @@ function appendFontAwesomeStyle() {
}
}

/**
* Append highlight.js script
*/
function appendHighlightJsScript() {
var highlightJsScript = document.createElement('script');
highlightJsScript.type = 'text/javascript';
highlightJsScript.src = chrome.extension.getURL('js/highlight.min.js');
document.head.appendChild(highlightJsScript);
}

/**
* Append css files
*/
function appendStyles() {
chrome.storage.local.get(THEME_KEY, function (items) {
var theme = items[THEME_KEY];
if (!theme) {
// Default theme
theme = 'asciidoctor';
}
var themeLink = document.createElement('link');
themeLink.rel = 'stylesheet';
themeLink.id = 'asciidoctor-style';
themeLink.href = chrome.extension.getURL('css/themes/' + theme + '.css');
document.head.appendChild(themeLink);

});
var githubHighlightLink = document.createElement('link');
githubHighlightLink.rel = 'stylesheet';
githubHighlightLink.id = 'github-highlight-style';
githubHighlightLink.href = chrome.extension.getURL('css/github.min.css');
document.head.appendChild(githubHighlightLink);
}

/**
* Show error message
* @param message The error message
Expand Down

0 comments on commit ab34c43

Please sign in to comment.