Skip to content

Commit

Permalink
Editor completely finished; all core markdown features working as int…
Browse files Browse the repository at this point in the history
…ended.
  • Loading branch information
BraedonM committed Dec 3, 2024
1 parent 7f1eb49 commit e5aaa8c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 16 deletions.
33 changes: 25 additions & 8 deletions src/Editor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ ${highlightedCode}

// Step 2: Process other Markdown elements
html = html
// Escape HTML special characters
.replace(/&/g, "&")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#039;")

// Math blocks ($$...$$)
.replace(/\$\$([\s\S]*?)\$\$/g, (_, math) => {
try {
Expand Down Expand Up @@ -133,14 +140,24 @@ ${highlightedCode}

// Italic
.replace(/\*(.*?)\*/g, '<em class="italic">$1</em>')
//
// // Paragraphs (adjust line breaks)
// .replace(/^(?!<[^>]*>)(.*$)/gm, (match) => {
// return match.trim() ? `<p>${match}</p>` : '';
// })
//
// // Clean up empty paragraphs
// .replace(/<p>\s*<\/p>/g, '');

// Strikethrough
.replace(/~~(.*?)~~/g, '<del>$1</del>')

// Inline code
.replace(/`(.*?)`/g, '<code class="bg-neutral-900 text-white px-2 py-1 rounded">$1</code>')

// Horizontal rule
.replace(/^\s*---\s*$/gm, '<hr class="border-scheme-500 border-opacity-50 border-t-2 mt-4 mb-4" />')

// Replace double-newlines with <br> tags
.replace(/\n\n/g, '<br>')

// When the only content on the line is a double space, replace it with a <br> tag
.replace(/^( )$/gm, '<br><br>')

// Replace two trailing spaces with <br> tags
.replace(/ $/gm, '<br>')
;

// Step 3: Reinsert code blocks
Expand Down
22 changes: 14 additions & 8 deletions src/Editor/sample_text.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
# Header 1
## Header 2

### Header 3
#### Header 4
##### Header 5
###### Header 6

Body text
(same line)
(this text is on the same line)

This text is a new line

Spaced line (the line above contains 2 spaces)

**Bold**

(different line)
*Italic*

[link](https://www.google.com)

(spaced line)
---

Here is some `inline code`

```python
# Sample file
Expand All @@ -22,10 +30,8 @@ for i in range(10):
print(x)
```

**Bold**
*Italic*

[link](https://www.google.com)
$y = x^2$
$$f(x) = 3x^2+8x-12$$

1. one
2. two
Expand Down

0 comments on commit e5aaa8c

Please sign in to comment.