git.iko.soy/rowtype-yoga/psfp
on master help sign in
Some work on markdown
dc3b89eMark Eibes
blog/.psc-ide-port+1−1
@@ -1 +1 @@
1−15530
1+15750
blog/src/components/FillInTheGaps.purs+9−11
@@ -3,17 +3,17 @@ module FillInTheGaps where
3import Prelude
3import Prelude
4
4
5import Data.Array as A
5import Data.Array as A
6−import Data.Maybe (Maybe(..), fromMaybe)
6+import Data.Maybe (fromMaybe)
7import Data.String (Pattern(..), split)
7import Data.String (Pattern(..), split)
8import Data.Tuple.Nested ((/\))
8import Data.Tuple.Nested ((/\))
9import Effect (Effect)
9import Effect (Effect)
10−import Effect.Unsafe (unsafePerformEffect)
11import Justifill (justifill)
10import Justifill (justifill)
12import Partial.Unsafe (unsafeCrashWith)
11import Partial.Unsafe (unsafeCrashWith)
13import React.Basic (JSX, ReactComponent, element)
12import React.Basic (JSX, ReactComponent, element)
14import React.Basic.DOM as R
13import React.Basic.DOM as R
15−import React.Basic.Hooks (ReactChildren, componentWithChildren, reactChildrenToArray, useState)
14+import React.Basic.Hooks (component, useState)
16import React.Basic.Hooks as React
15import React.Basic.Hooks as React
16+import Yoga.Helpers (intersperse)
17import Yoga.InlineCode.Component as InlineCode
17import Yoga.InlineCode.Component as InlineCode
18
18
19data Segment = Filler String | Hole String
19data Segment = Filler String | Hole String
@@ -36,19 +36,17 @@ updateLine idx v arr = fromMaybe [] (A.modifyAt idx f arr)
36 Filler s -> unsafeCrashWith "Updated a filler"
36 Filler s -> unsafeCrashWith "Updated a filler"
37 Hole _ -> Hole v
37 Hole _ -> Hole v
38
38
39−
40−fillInTheGaps :: ReactComponent { children :: ReactChildren String }
39+mkFillInTheGaps :: Effect (ReactComponent { code :: String })
41−fillInTheGaps = unsafePerformEffect do
40+mkFillInTheGaps = do
42 ic <- InlineCode.makeComponent
41 ic <- InlineCode.makeComponent
43− componentWithChildren "InlineCodeWithChildren" \{ children } -> React.do
42+ component "FillInTheGaps" \{ code } -> React.do
44 let
43 let
45 separator = "???"
44 separator = "???"
46− child = children # reactChildrenToArray # A.head # fromMaybe "gurki"
47− lines = split (Pattern "\n") child
45+ lines = split (Pattern "\n") code
48− rawSegments = split (Pattern separator)
46+ rawSegments = split (Pattern separator) >>> intersperse separator
49 toSegment = case _ of
47 toSegment = case _ of
50 x | x == separator -> Hole ""
48 x | x == separator -> Hole ""
51 other -> Filler other
49 other -> Filler other
52 initialSegments = lines <#> \line -> rawSegments line <#> toSegment
50 initialSegments = lines <#> \line -> rawSegments line <#> toSegment
53− (segments :: Array (Array Segment)) /\ modifySegments <- useState initialSegments
51+ segments /\ modifySegments <- useState initialSegments
54 pure $ renderSegments ic (modifySegments) segments
52 pure $ renderSegments ic (modifySegments) segments
blog/src/components/PSLayout.purs+12−8
@@ -11,6 +11,7 @@ import Data.Nullable as Nullable
11import Data.Semigroup.Foldable (intercalateMap)
11import Data.Semigroup.Foldable (intercalateMap)
12import Data.String as String
12import Data.String as String
13import Effect (Effect)
13import Effect (Effect)
14+import FillInTheGaps (mkFillInTheGaps)
14import JSS (jss, jssClasses)
15import JSS (jss, jssClasses)
15import Justifill (justifill)
16import Justifill (justifill)
16import Milkis.Impl (FetchImpl)
17import Milkis.Impl (FetchImpl)
@@ -88,6 +89,7 @@ mkMdxProviderComponent ∷
88mkMdxProviderComponent fetchImpl = do
89mkMdxProviderComponent fetchImpl = do
89 cssBaseline <- mkCssBaseline
90 cssBaseline <- mkCssBaseline
90 editor <- mkCompileEditor fetchImpl
91 editor <- mkCompileEditor fetchImpl
92+ fillInTheGaps <- mkFillInTheGaps
91 sidebar <- mkSidebar
93 sidebar <- mkSidebar
92 header <- mkHeader
94 header <- mkHeader
93 yogaInlineCode <- InlineCode.makeComponent
95 yogaInlineCode <- InlineCode.makeComponent
@@ -168,14 +170,16 @@ mkMdxProviderComponent fetchImpl = do
168 )
170 )
169
171
170 language = fromMaybe "" (classNameQ >>= String.stripPrefix (String.Pattern "language-"))
172 language = fromMaybe "" (classNameQ >>= String.stripPrefix (String.Pattern "language-"))
171− if isCode then
173+ case isCode, language of
174+ true, "puregaps" ->
175+ element fillInTheGaps { code: fromMaybe "" codeQ}
176+ true, _ ->
172− element editor
177+ element editor
173− { initialCode: fromMaybe "" codeQ
178+ { initialCode: fromMaybe "" codeQ
174− , height
179+ , height
175− , language
180+ , language
176− }
181+ }
177− else
178− element (unsafeCreateDOMComponent "pre") props
182+ false, _ -> element (unsafeCreateDOMComponent "pre") props
179 }
183 }
180 pure
184 pure
181 $ baseline
185 $ baseline
blog/src/components/fillInTheGaps.jsdeleted−2
@@ -1,2 +0,0 @@
1−const FillInTheGaps = require("./FillInTheGaps.purs").fillInTheGaps
2−export default FillInTheGaps;
blog/src/pages/optional.mdx+2−4
@@ -1,17 +1,15 @@
1import Layout from '../components/layout'
1import Layout from '../components/layout'
2import SEO from '../components/seo'
2import SEO from '../components/seo'
3−import FillInTheGaps from '../components/fillInTheGaps'
4
3
5<SEO title="Home" keywords={['gatsby', 'application', 'react']} />
4<SEO title="Home" keywords={['gatsby', 'application', 'react']} />
6
5
7# Optional
6# Optional
8
7
9−<div>Udo</div>
8+```puregaps
10−<FillInTheGaps>module Main where
11import Batteries
9import Batteries
12
10
13main :: Effect Unit
11main :: Effect Unit
14main = log "???"
12main = log "???"
15−</FillInTheGaps>
13+```
16
14
17## Hans Hölzel
15## Hans Hölzel
components/src/Yoga/Helpers.purs+11
@@ -1,6 +1,7 @@
1module Yoga.Helpers where
1module Yoga.Helpers where
2
2
3import Prelude
3import Prelude
4+import Data.Array (head, tail, (:))
4import Data.Maybe (Maybe(..), fromMaybe)
5import Data.Maybe (Maybe(..), fromMaybe)
5
6
6fromMaybeFlipped ∷ ∀ a. Maybe a -> a -> a
7fromMaybeFlipped ∷ ∀ a. Maybe a -> a -> a
@@ -13,3 +14,13 @@ ifJustTrue option value = if option == Just true then value else mempty
13
14
14ifJustFalse ∷ ∀ m. Monoid m => Maybe Boolean -> m -> m
15ifJustFalse ∷ ∀ m. Monoid m => Maybe Boolean -> m -> m
15ifJustFalse option value = if option == Just false then value else mempty
16ifJustFalse option value = if option == Just false then value else mempty
17+
18+intersperse ∷ ∀ a. a -> Array a -> Array a
19+intersperse sep xs = case head xs, tail xs ?|| [] of
20+ Nothing, _ -> []
21+ Just x, xs' -> x : prependToAll sep xs'
22+
23+prependToAll ∷ ∀ a. a -> Array a -> Array a
24+prependToAll sep xs = case head xs, tail xs ?|| [] of
25+ Nothing, _ -> []
26+ Just x, xs' -> sep : x : prependToAll sep xs'