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
0
Issues
0
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
Grégoire Locqueville
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
Hide 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 @@
...
@@ -90,11 +90,15 @@
margin-left
:
25px
;
margin-left
:
25px
;
padding-left
:
25px
;
padding-left
:
25px
;
}
}
.code-editor
.editor
.html
ul
li
{
.code-editor
.editor
.html
.language-md
ul
li
{
list-style
:
disc
!important
;
list-style
:
disc
!important
;
}
}
.code-editor
.editor
.html
ol
li
{
.code-editor
.editor
.html
.language-md
ol
li
{
list-style
:
decimal
!important
;
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 */
/*# sourceMappingURL=CodeEditor.css.map */
dist/styles/CodeEditor.sass
View file @
69ee823b
...
@@ -74,9 +74,13 @@
...
@@ -74,9 +74,13 @@
flex-grow
:
2
flex-grow
:
2
margin-left
:
25px
margin-left
:
25px
padding-left
:
25px
padding-left
:
25px
ul
&
.language-md
li
ul
list-style
:
disc
!
important
li
ol
list-style
:
disc
!
important
li
ol
list-style
:
decimal
!
important
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 =
...
@@ -51,9 +51,8 @@ type Props =
-- Fixes newlines in code
-- Fixes newlines in code
-- This is useful eg for proper rendering of the textarea overlay
-- This is useful eg for proper rendering of the textarea overlay
codeNlFix :: CodeType -> Code -> Code
codeNlFix :: CodeType -> Code -> Code
codeNlFix Markdown "" = " "
codeNlFix _ "" = " "
codeNlFix Markdown c = if endsWith "\n" c then (c <> " ") else c
codeNlFix _ c = if endsWith "\n" c then (c <> " ") else c
codeNlFix _ c = c
compile :: CodeType -> Code -> Either Error Html
compile :: CodeType -> Code -> Either Error Html
compile JSON code = result
compile JSON code = result
...
@@ -64,6 +63,11 @@ compile JSON code = result
...
@@ -64,6 +63,11 @@ compile JSON code = result
Right parsed -> Right $ R2.stringify parsed 2
Right parsed -> Right $ R2.stringify parsed 2
compile Markdown code = Right $ compileMd $ codeNlFix Markdown code
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?
-- TODO Replace with markdown-it?
-- https://pursuit.purescript.org/packages/purescript-markdown-it
-- https://pursuit.purescript.org/packages/purescript-markdown-it
compileMd' :: forall e. MD.ToMarkupOptions e -> String -> String
compileMd' :: forall e. MD.ToMarkupOptions e -> String -> String
...
@@ -113,7 +117,7 @@ codeEditorCpt = R.hooksComponent "G.C.CE.CodeEditor" cpt
...
@@ -113,7 +117,7 @@ codeEditorCpt = R.hooksComponent "G.C.CE.CodeEditor" cpt
, on: { change: onEditChange controls }
, on: { change: onEditChange controls }
, placeholder: "Type some code..."
, placeholder: "Type some code..."
, ref: controls.codeElRef } [ ]
, ref: controls.codeElRef } [ ]
, H.pre { className:
""
, H.pre { className:
(langClass $ fst controls.codeType)
-- , contentEditable: "true"
-- , contentEditable: "true"
, ref: controls.codeOverlayElRef
, ref: controls.codeOverlayElRef
, rows: 30
, rows: 30
...
@@ -122,7 +126,7 @@ codeEditorCpt = R.hooksComponent "G.C.CE.CodeEditor" cpt
...
@@ -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: "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
, ref: controls.htmlElRef
} []
} []
]
]
...
@@ -137,6 +141,10 @@ codeEditorCpt = R.hooksComponent "G.C.CE.CodeEditor" cpt
...
@@ -137,6 +141,10 @@ codeEditorCpt = R.hooksComponent "G.C.CE.CodeEditor" cpt
dividerHidden Both = ""
dividerHidden Both = ""
dividerHidden _ = "hidden"
dividerHidden _ = "hidden"
langClass :: CodeType -> String
langClass JSON = "language-json"
langClass Markdown = "language-md"
previewHidden :: ViewType -> String
previewHidden :: ViewType -> String
previewHidden Preview = ""
previewHidden Preview = ""
previewHidden Both = ""
previewHidden Both = ""
...
@@ -171,6 +179,7 @@ renderHtml code {codeType: (codeType /\ _), htmlElRef, error: (_ /\ setError)} =
...
@@ -171,6 +179,7 @@ renderHtml code {codeType: (codeType /\ _), htmlElRef, error: (_ /\ setError)} =
Right compiled -> do
Right compiled -> do
setError $ const Nothing
setError $ const Nothing
_ <- pure $ (htmlEl .= "innerHTML") compiled
_ <- pure $ (htmlEl .= "innerHTML") compiled
previewPostProcess codeType htmlEl
pure unit
pure unit
toolbar :: Record Controls -> R.Element
toolbar :: Record Controls -> R.Element
...
@@ -192,8 +201,8 @@ toolbarCpt = R.hooksComponent "G.C.CE.toolbar" cpt
...
@@ -192,8 +201,8 @@ toolbarCpt = R.hooksComponent "G.C.CE.toolbar" cpt
-- Handle rerendering of preview when viewType changed
-- Handle rerendering of preview when viewType changed
onChangeCodeType :: forall e. Record Controls -> e -> Effect Unit
onChangeCodeType :: forall e. Record Controls -> e -> Effect Unit
onChangeCodeType controls _ = do
onChangeCodeType controls _ = do
_ <- renderHtml (R.readRef controls.editorCodeRef) controls
setCodeOverlay controls (R.readRef controls.editorCodeRef)
pure unit
renderHtml (R.readRef controls.editorCodeRef) controls
type ErrorComponentProps =
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