Skip to content

Commit

Permalink
Merge pull request #227 from earthpulse/171-markdown-html-interaction
Browse files Browse the repository at this point in the history
171 markdown html interaction
  • Loading branch information
juansensio authored Aug 27, 2024
2 parents a8cc32d + 12b05ae commit 39251a3
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 16 deletions.
5 changes: 4 additions & 1 deletion eotdl/eotdl/datasets/ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import json
import frontmatter
import markdown
from markdown.extensions.tables import TableExtension
from markdown.extensions.fenced_code import FencedCodeExtension


from ..auth import with_auth
from .metadata import Metadata
from ..repos import DatasetsAPIRepo, FilesAPIRepo
Expand Down Expand Up @@ -74,7 +76,8 @@ def ingest_folder(
# retrieve dataset (create if doesn't exist)
dataset = retrieve_dataset(metadata, user)
if content:
content = markdown.markdown(content, extensions=[FencedCodeExtension()])
content = markdown.markdown(content, extensions=[TableExtension(),FencedCodeExtension()])

update_metadata = True
if "description" in dataset:
# do not do this if the dataset is new, only if it already exists
Expand Down
3 changes: 2 additions & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"leaflet": "1.7.1",
"quill": "^1.3.7",
"streamsaver": "^2.0.6",
"turndown": "^7.2.0"
"turndown": "^7.2.0",
"turndown-plugin-gfm": "^1.0.2"
}
}
23 changes: 10 additions & 13 deletions ui/src/routes/datasets/TextEditor.svelte
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
<script>
// import { onMount } from "svelte";
import { Carta, MarkdownEditor } from "carta-md";
import "carta-md/default.css"; /* Default theme */
import "$styles/carta-md.css";
import DOMPurify from "isomorphic-dompurify";
import TurndownService from "turndown";
import { Carta, MarkdownEditor } from 'carta-md';
import 'carta-md/default.css'; /* Default theme */
import "$styles/carta-md.css"
import DOMPurify from 'isomorphic-dompurify';
import TurndownService from 'turndown';
import {tables} from "turndown-plugin-gfm";
var x = window.matchMedia("(max-width: 640px)")
export let content;
var x = window.matchMedia("(max-width: 640px)");
let sm = x.matches ? true : false;
let normal = x.matches ? false : true;
// Attach listener function on state changes
Expand All @@ -27,10 +25,9 @@
sanitizer: DOMPurify.sanitize,
});
var turndownService = new TurndownService({
codeBlockStyle: "fenced",
preformattedCode: true,
});
export let content;
var turndownService = new TurndownService({codeBlockStyle:"fenced", preformattedCode:true})
turndownService.use(tables);
let value = turndownService.turndown(content);
const renderHtml = async () => {
Expand Down
6 changes: 6 additions & 0 deletions ui/src/styles/carta-md.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
.carta-renderer pre {
@apply bg-[rgb(31,41,55)] w-fit rounded-md my-2 py-[2px] px-1 text-white
}
.carta-renderer table {
@apply my-2 py-[2px] px-1 border-2
}
.carta-renderer td,.carta-renderer th{
@apply border-[1px] border-slate-300 p-1
}

.carta-editor{
@apply w-[100%] max-w-[99%]
Expand Down
7 changes: 6 additions & 1 deletion ui/src/styles/dataset.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
.content {
@apply flex flex-col max-w-full gap-4;
}

.content table {
@apply my-2 py-[2px] px-1 border-2
}
.content td,.content th{
@apply border-[1px] border-slate-300 p-1
}
.content a {
@apply text-green-200 underline;
}
Expand Down

0 comments on commit 39251a3

Please sign in to comment.