Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
128
Issues
128
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
purescript-gargantext
Commits
69ee823b
Commit
69ee823b
authored
Jan 22, 2020
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[CodeEditor] postprocessing in html preview, styling fixes
Syntax highlighting of JSON in the preview.
parent
c670fc65
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
15 deletions
+32
-15
CodeEditor.css
dist/styles/CodeEditor.css
+6
-2
CodeEditor.sass
dist/styles/CodeEditor.sass
+10
-6
CodeEditor.purs
src/Gargantext/Components/CodeEditor.purs
+16
-7
No files found.
dist/styles/CodeEditor.css
View file @
69ee823b
...
...
@@ -90,11 +90,15 @@
margin-left
:
25px
;
padding-left
:
25px
;
}
.code-editor
.editor
.html
ul
li
{
.code-editor
.editor
.html
.language-md
ul
li
{
list-style
:
disc
!important
;
}
.code-editor
.editor
.html
ol
li
{
.code-editor
.editor
.html
.language-md
ol
li
{
list-style
:
decimal
!important
;
}
.code-editor
.editor
.html.language-json
{
font-family
:
Fira
code
,
Fira
Mono
,
Consolas
,
Menlo
,
Courier
,
monospace
;
white-space
:
pre
;
}
/*# sourceMappingURL=CodeEditor.css.map */
dist/styles/CodeEditor.sass
View file @
69ee823b
...
...
@@ -74,9 +74,13 @@
flex-grow
:
2
margin-left
:
25px
padding-left
:
25px
&
.language-md
ul
li
list-style
:
disc
!
important
ol
li
list-style
:
decimal
!
important
&
.language-json
font-family
:
Fira
code
,
Fira
Mono
,
Consolas
,
Menlo
,
Courier
,
monospace
white-space
:
pre
src/Gargantext/Components/CodeEditor.purs
View file @
69ee823b
...
...
@@ -51,9 +51,8 @@ type Props =
-- Fixes newlines in code
-- This is useful eg for proper rendering of the textarea overlay
codeNlFix :: CodeType -> Code -> Code
codeNlFix Markdown "" = " "
codeNlFix Markdown c = if endsWith "\n" c then (c <> " ") else c
codeNlFix _ c = c
codeNlFix _ "" = " "
codeNlFix _ c = if endsWith "\n" c then (c <> " ") else c
compile :: CodeType -> Code -> Either Error Html
compile JSON code = result
...
...
@@ -64,6 +63,11 @@ compile JSON code = result
Right parsed -> Right $ R2.stringify parsed 2
compile Markdown code = Right $ compileMd $ codeNlFix Markdown code
previewPostProcess :: CodeType -> Element -> Effect Unit
previewPostProcess Markdown _ = pure unit
previewPostProcess JSON htmlEl = do
HLJS.highlightBlock htmlEl
-- TODO Replace with markdown-it?
-- https://pursuit.purescript.org/packages/purescript-markdown-it
compileMd' :: forall e. MD.ToMarkupOptions e -> String -> String
...
...
@@ -113,7 +117,7 @@ codeEditorCpt = R.hooksComponent "G.C.CE.CodeEditor" cpt
, on: { change: onEditChange controls }
, placeholder: "Type some code..."
, ref: controls.codeElRef } [ ]
, H.pre { className:
""
, H.pre { className:
(langClass $ fst controls.codeType)
-- , contentEditable: "true"
, ref: controls.codeOverlayElRef
, rows: 30
...
...
@@ -122,7 +126,7 @@ codeEditorCpt = R.hooksComponent "G.C.CE.CodeEditor" cpt
]
]
, H.div { className: "v-divider " <> (dividerHidden $ fst controls.viewType) } [ H.text " " ]
, H.div { className: "html " <> (previewHidden $ fst controls.viewType)
, H.div { className: "html " <> (
langClass $ fst controls.codeType) <> (
previewHidden $ fst controls.viewType)
, ref: controls.htmlElRef
} []
]
...
...
@@ -137,6 +141,10 @@ codeEditorCpt = R.hooksComponent "G.C.CE.CodeEditor" cpt
dividerHidden Both = ""
dividerHidden _ = "hidden"
langClass :: CodeType -> String
langClass JSON = "language-json"
langClass Markdown = "language-md"
previewHidden :: ViewType -> String
previewHidden Preview = ""
previewHidden Both = ""
...
...
@@ -171,6 +179,7 @@ renderHtml code {codeType: (codeType /\ _), htmlElRef, error: (_ /\ setError)} =
Right compiled -> do
setError $ const Nothing
_ <- pure $ (htmlEl .= "innerHTML") compiled
previewPostProcess codeType htmlEl
pure unit
toolbar :: Record Controls -> R.Element
...
...
@@ -192,8 +201,8 @@ toolbarCpt = R.hooksComponent "G.C.CE.toolbar" cpt
-- Handle rerendering of preview when viewType changed
onChangeCodeType :: forall e. Record Controls -> e -> Effect Unit
onChangeCodeType controls _ = do
_ <- renderHtml (R.readRef controls.editorCodeRef) controls
pure unit
setCodeOverlay controls (R.readRef controls.editorCodeRef)
renderHtml (R.readRef controls.editorCodeRef) controls
type ErrorComponentProps =
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment