Commit 900956af authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[Markdown] first draft of the markdown editor

parent 7b864b3a
...@@ -1475,6 +1475,21 @@ ...@@ -1475,6 +1475,21 @@
"repo": "https://github.com/justinwoo/purescript-makkori.git", "repo": "https://github.com/justinwoo/purescript-makkori.git",
"version": "v1.0.0" "version": "v1.0.0"
}, },
"markdown": {
"dependencies": [
"precise"
],
"repo": "https://github.com/poorscript/purescript-markdown",
"version": "master"
},
"markdown-smolder": {
"dependencies": [
"markdown",
"smolder"
],
"repo": "https://github.com/poorscript/purescript-markdown-smolder",
"version": "master"
},
"math": { "math": {
"dependencies": [], "dependencies": [],
"repo": "https://github.com/purescript/purescript-math.git", "repo": "https://github.com/purescript/purescript-math.git",
...@@ -2041,6 +2056,13 @@ ...@@ -2041,6 +2056,13 @@
"repo": "https://github.com/purescript-node/purescript-posix-types.git", "repo": "https://github.com/purescript-node/purescript-posix-types.git",
"version": "v4.0.0" "version": "v4.0.0"
}, },
"precise": {
"dependencies": [
"prelude"
],
"repo": "https://github.com/poorscript/purescript-precise",
"version": "master"
},
"prelude": { "prelude": {
"dependencies": [], "dependencies": [],
"repo": "https://github.com/purescript/purescript-prelude.git", "repo": "https://github.com/purescript/purescript-prelude.git",
......
...@@ -191,6 +191,28 @@ let additions = ...@@ -191,6 +191,28 @@ let additions =
[ "aff", "arraybuffer-types", "web-file", "web-html" ] [ "aff", "arraybuffer-types", "web-file", "web-html" ]
"https://github.com/nwolverson/purescript-dom-filereader" "https://github.com/nwolverson/purescript-dom-filereader"
"v5.0.0" "v5.0.0"
, markdown =
mkPackage
[ "precise" ]
{- "https://github.com/slamdata/purescript-markdown"
"v12.0.0" -}
"https://github.com/poorscript/purescript-markdown"
"master"
, markdown-smolder =
mkPackage
[ "markdown"
, "smolder" ]
{- "https://github.com/hgiasac/purescript-markdown-smolder"
"v2.0.1" -}
"https://github.com/poorscript/purescript-markdown-smolder"
"master"
, precise =
mkPackage
[ "prelude" ]
{- "https://github.com/purescript-contrib/purescript-precise"
"v3.0.1" -}
"https://github.com/poorscript/purescript-precise"
"master"
, reactix = , reactix =
mkPackage mkPackage
[ "aff" [ "aff"
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
"globals", "globals",
"integers", "integers",
"js-timers", "js-timers",
"markdown-smolder",
"math", "math",
"maybe", "maybe",
"nonempty", "nonempty",
...@@ -28,6 +29,7 @@ ...@@ -28,6 +29,7 @@
"read", "read",
"routing", "routing",
"sequences", "sequences",
"smolder",
"spec-discovery", "spec-discovery",
"spec-quickcheck", "spec-quickcheck",
"string-parsers", "string-parsers",
......
module Gargantext.Components.MarkdownEditor where
import Data.Either (either, Either(..))
import Prelude (($), (>>>), identity, pure)
import Reactix as R
import Reactix.DOM.HTML as H
import Text.Markdown.SlamDown.Parser (parseMd)
import Text.Markdown.SlamDown.Smolder as MD
import Text.Markdown.SlamDown.Syntax (SlamDownP(..))
import Text.Smolder.Renderer.String (render)
type Props =
( md :: String
, nodeId :: Int
)
compileMd' :: forall e. MD.ToMarkupOptions e -> String -> String
compileMd' options input =
either identity (MD.toMarkup' options >>> render)
(parseMd input :: Either String (SlamDownP String))
compileMd :: String -> String
compileMd = compileMd' MD.defaultToMarkupOptions
markdownEditor :: Record Props -> R.Element
markdownEditor p = R.createElement markdownEditorCpt p []
markdownEditorCpt :: R.Component Props
markdownEditorCpt = R.hooksComponent "G.C.MarkdownEditor" cpt
where
cpt {md, nodeId} _ =
pure $
H.div {} [ H.text $ compileMd md ]
...@@ -9,6 +9,7 @@ import Effect.Exception (error) ...@@ -9,6 +9,7 @@ import Effect.Exception (error)
import Reactix as R import Reactix as R
import Reactix.DOM.HTML as H import Reactix.DOM.HTML as H
import Gargantext.Prelude import Gargantext.Prelude
import Gargantext.Components.MarkdownEditor (markdownEditor)
import Gargantext.Components.Node (NodePoly(..), HyperdataList) import Gargantext.Components.Node (NodePoly(..), HyperdataList)
import Gargantext.Types (NodeType(..), AffTableResult) import Gargantext.Types (NodeType(..), AffTableResult)
import Gargantext.Routes (SessionRoute(NodeAPI, Children)) import Gargantext.Routes (SessionRoute(NodeAPI, Children))
...@@ -24,9 +25,13 @@ corpusLayoutCpt = R.staticComponent "G.P.Corpus.corpusLayout" cpt ...@@ -24,9 +25,13 @@ corpusLayoutCpt = R.staticComponent "G.P.Corpus.corpusLayout" cpt
where where
cpt {nodeId} _ = cpt {nodeId} _ =
H.div {} H.div {}
[ H.iframe { src: gargMd , width: "100%", height: "100%", style: {"border-style": "none"}} [] [
markdownEditor {md, nodeId}
--H.iframe { src: gargMd , width: "100%", height: "100%", style: {"border-style": "none"}} []
] ]
gargMd = "https://hackmd.iscpif.fr/g9Aah4iwQtCayIzsKQjA0Q#" gargMd = "https://hackmd.iscpif.fr/g9Aah4iwQtCayIzsKQjA0Q#"
md = "# Hello world"
newtype CorpusInfo = newtype CorpusInfo =
CorpusInfo CorpusInfo
{ title :: String { title :: String
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment