Skip to content

Commit

Permalink
convert markdown to html
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsboost committed Mar 14, 2024
1 parent 2feb35e commit 148b461
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 32 deletions.
72 changes: 49 additions & 23 deletions go/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@
This type describes a line in the document. It is created
on-demand when lines are [queried](https://codemirror.net/6/docs/ref/#state.Text.lineAt).
*/
let Line$1 = class Line {
class Line$1 {
/**
@internal
*/
Expand Down Expand Up @@ -557,7 +557,7 @@
The length of the line (not including any line break after it).
*/
get length() { return this.to - this.from; }
};
}
function clip(text, from, to) {
from = Math.max(0, Math.min(text.length, from));
return [from, Math.max(from, Math.min(text.length, to))];
Expand Down Expand Up @@ -3065,7 +3065,7 @@
/**
A range associates a value with a range of positions.
*/
let Range$1 = class Range {
class Range$1 {
constructor(
/**
The range's start position.
Expand All @@ -3087,9 +3087,9 @@
@internal
*/
static create(from, to, value) {
return new Range(from, to, value);
return new Range$1(from, to, value);
}
};
}
function cmpRange(a, b) {
return a.from - b.from || a.value.startSide - b.value.startSide;
}
Expand Down Expand Up @@ -4185,6 +4185,7 @@
};

var chrome$1 = typeof navigator != "undefined" && /Chrome\/(\d+)/.exec(navigator.userAgent);
typeof navigator != "undefined" && /Gecko\/\d+/.test(navigator.userAgent);
var mac = typeof navigator != "undefined" && /Mac/.test(navigator.platform);
var ie$1 = typeof navigator != "undefined" && /MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);
var brokenModifierNames = mac || chrome$1 && +chrome$1[1] < 57;
Expand Down Expand Up @@ -15396,7 +15397,7 @@
get node() { return this; }
get next() { return this.parent; }
}
let TreeNode$2 = class TreeNode extends BaseNode {
class TreeNode$2 extends BaseNode {
constructor(_tree, from,
// Index in parent node, set to -1 if the node is not a direct child of _parent.node (overlay)
index, _parent) {
Expand Down Expand Up @@ -15425,8 +15426,8 @@
else if ((mode & IterMode.IncludeAnonymous) || (!next.type.isAnonymous || hasChild(next))) {
let mounted;
if (!(mode & IterMode.IgnoreMounts) && (mounted = MountedTree.get(next)) && !mounted.overlay)
return new TreeNode(mounted.tree, start, i, parent);
let inner = new TreeNode(next, start, i, parent);
return new TreeNode$2(mounted.tree, start, i, parent);
let inner = new TreeNode$2(next, start, i, parent);
return (mode & IterMode.IncludeAnonymous) || !inner.type.isAnonymous ? inner
: inner.nextChild(dir < 0 ? next.children.length - 1 : 0, dir, pos, side);
}
Expand All @@ -15453,7 +15454,7 @@
for (let { from, to } of mounted.overlay) {
if ((side > 0 ? from <= rPos : from < rPos) &&
(side < 0 ? to >= rPos : to > rPos))
return new TreeNode(mounted.tree, mounted.overlay[0].from + this.from, -1, this);
return new TreeNode$2(mounted.tree, mounted.overlay[0].from + this.from, -1, this);
}
}
return this.nextChild(0, 1, pos, side, mode);
Expand All @@ -15479,7 +15480,7 @@
@internal
*/
toString() { return this._tree.toString(); }
};
}
function getChildren(node, type, before, after) {
let cur = node.cursor(), result = [];
if (!cur.firstChild())
Expand Down Expand Up @@ -16701,7 +16702,7 @@
return false;
}
}
let FragmentCursor$2 = class FragmentCursor {
class FragmentCursor$2 {
constructor(fragments) {
var _a;
this.fragments = fragments;
Expand Down Expand Up @@ -16757,7 +16758,7 @@
}
return result;
}
};
}
function punchRanges(outer, ranges) {
let copy = null, current = ranges;
for (let i = 1, j = 0; i < outer.length; i++) {
Expand Down Expand Up @@ -25727,7 +25728,7 @@
});
}
const none = [];
let Buffer$2 = class Buffer {
class Buffer$2 {
constructor(nodeSet) {
this.nodeSet = nodeSet;
this.content = [];
Expand All @@ -25751,9 +25752,9 @@
length
});
}
};
}
/// Elements are used to compose syntax nodes during parsing.
let Element$1 = class Element {
class Element$1 {
/// @internal
constructor(
/// The node's
Expand All @@ -25780,7 +25781,7 @@
toTree(nodeSet) {
return new Buffer$2(nodeSet).writeElements(this.children, -this.from).finish(this.type, this.to - this.from);
}
};
}
class TreeElement {
constructor(tree, from) {
this.tree = tree;
Expand Down Expand Up @@ -26208,7 +26209,7 @@
// These are blocks that can span blank lines, and should thus only be
// reused if their next sibling is also being reused.
const NotLast = [Type.CodeBlock, Type.ListItem, Type.OrderedList, Type.BulletList];
let FragmentCursor$1 = class FragmentCursor {
class FragmentCursor$1 {
constructor(fragments, input) {
this.fragments = fragments;
this.input = input;
Expand Down Expand Up @@ -26303,7 +26304,7 @@
}
return end - start;
}
};
}
// Convert an input-stream-relative position to a
// Markdown-doc-relative position by subtracting the size of all input
// gaps before `abs`.
Expand Down Expand Up @@ -26677,7 +26678,7 @@
that external code such as a tokenizer can use to get information
about the parse state.
*/
let Stack$2 = class Stack {
class Stack$2 {
/**
@internal
*/
Expand Down Expand Up @@ -26769,7 +26770,7 @@
*/
static start(p, state, pos = 0) {
let cx = p.parser.context;
return new Stack(p, [], state, pos, pos, 0, [], 0, cx ? new StackContext(cx, cx.start) : null, 0, null);
return new Stack$2(p, [], state, pos, pos, 0, [], 0, cx ? new StackContext(cx, cx.start) : null, 0, null);
}
/**
The stack's current [context](#lr.ContextTracker) value, if
Expand Down Expand Up @@ -26962,7 +26963,7 @@
// Make sure parent points to an actual parent with content, if there is such a parent.
while (parent && base == parent.bufferBase)
parent = parent.parent;
return new Stack(this.p, this.stack.slice(), this.state, this.reducePos, this.pos, this.score, buffer, base, this.curContext, this.lookAhead, parent);
return new Stack$2(this.p, this.stack.slice(), this.state, this.reducePos, this.pos, this.score, buffer, base, this.curContext, this.lookAhead, parent);
}
// Try to recover from an error by 'deleting' (ignoring) one token.
/**
Expand Down Expand Up @@ -27190,7 +27191,7 @@
if (this.lookAhead > 0)
this.emitLookAhead();
}
};
}
class StackContext {
constructor(tracker, context) {
this.tracker = tracker;
Expand Down Expand Up @@ -157087,6 +157088,27 @@ ${"-".repeat(err.pos)}^`;
// Function to update previews
updatePreview: (runManually = false) => {
app.updateStorage();
const generateMarkdownCode = () => {
// Convert Markdown to HTML using Marked.js
const htmlContent = marked.parse(project.markdown);

// render html
return `<!DOCTYPE html data-theme="dark">
<html>
<head>
<title>${project.title}</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="${project.description}">
<link rel="stylesheet" href="libraries/pico/pico.classless.min.css">
</head>
<body>
<main>
${htmlContent}
</main>
</body>
</html>`;
};
const generateHtmlCode = () => {
const tailwindStyle =
".wrapper_yOR7u {left: 0!important; width: 100%!important; border-radius: 15px 15px 0 0!important; z-index: 99999999;} .btn_yOR7u { cursor: pointer; background: inherit; padding: 0 0.5rem; margin: inherit; margin-right: 0px; border: inherit; color: #fff!important; } .nav_yOR7u {padding-bottom: 14px!important;} .line_yOR7u {background: inherit!important;}";
Expand Down Expand Up @@ -157148,7 +157170,11 @@ ${"-".repeat(err.pos)}^`;

// Open, write HTML code, and close the content document
previewDoc.open();
previewDoc.write(generateHtmlCode());
if (document.querySelector("[data-toggletab=markdown]").classList.contains("text-blue-500")) {
previewDoc.write(generateMarkdownCode());
} else {
previewDoc.write(generateHtmlCode());
}
previewDoc.close();
},

Expand Down
27 changes: 26 additions & 1 deletion go/editor.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,27 @@ const app = {
// Function to update previews
updatePreview: (runManually = false) => {
app.updateStorage();
const generateMarkdownCode = () => {
// Convert Markdown to HTML using Marked.js
const htmlContent = marked.parse(project.markdown);

// render html
return `<!DOCTYPE html data-theme="dark">
<html>
<head>
<title>${project.title}</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="${project.description}">
<link rel="stylesheet" href="libraries/pico/pico.classless.min.css">
</head>
<body>
<main>
${htmlContent}
</main>
</body>
</html>`;
};
const generateHtmlCode = () => {
const tailwindStyle =
".wrapper_yOR7u {left: 0!important; width: 100%!important; border-radius: 15px 15px 0 0!important; z-index: 99999999;} .btn_yOR7u { cursor: pointer; background: inherit; padding: 0 0.5rem; margin: inherit; margin-right: 0px; border: inherit; color: #fff!important; } .nav_yOR7u {padding-bottom: 14px!important;} .line_yOR7u {background: inherit!important;}";
Expand Down Expand Up @@ -662,7 +683,11 @@ const app = {

// Open, write HTML code, and close the content document
previewDoc.open();
previewDoc.write(generateHtmlCode());
if (document.querySelector("[data-toggletab=markdown]").classList.contains("text-blue-500")) {
previewDoc.write(generateMarkdownCode());
} else {
previewDoc.write(generateHtmlCode());
}
previewDoc.close();
},

Expand Down
Loading

0 comments on commit 148b461

Please sign in to comment.