Create a custom inline styler.
Custom.inline "intro"
(\string styling ->
let
txt =
String.trim string
in
if txt == "" then
[]
else
[ Element.el [ Element.alignLeft, Font.size 48 ]
(Element.text (String.toUpper (String.slice 0 1 txt)))
, Element.el [ Font.size 24 ]
(Element.text (String.toUpper (String.dropLeft 1 txt)))
]
)When applied via parseWith, can then be used in markup like the following
{drop| Lorem Ipsum is simply dummy text } of the printing and...It will turn the first letter into a dropped capital and lead in with small caps
styling is the styling record that is passed in the options of parseWith. This means you can make an inline element that can be paragraph via the options.
A simple block that will insert Elm html.
import Element
import Element.Font as Font
import Mark.Custom as Custom
myParser =
Mark.parseWith
{ styling = Mark.defaultStyling
, inlines = []
, blocks =
[ Custom.block "red"
(\styling model ->
Element.el
[ Font.color (Element.rgb 1 0 0) ]
(Element.text "Some statically defined, red text!")
)
]
}Which can then be used in your markup like so:
| redThe element you defined will show up there.
Same as block, but you can parse one parameter as well.
For example, here's how the builtin block, image, using block2 and two Custom.string parameters.
Custom.block2 "image"
(\src description styling ->
Element.image
[]
{ src = String.trim src
, description = String.trim description
}
)
Custom.string
Custom.stringWhich can then be used in your markup:
| image "http://placekitten/200/500"
"Here's a great picture of my cat, pookie.""or as
| image
"http://placekitten/200/500"
"Here's a great picture of my cat, pookie.""A parameter to use with block1 or block2.
Define a list of options. Useful for working with custom types.
A block that expects a single paragraph of styled text as input. The header block that is built in uses this.
| header
My super sweet, /styled/ header.Note The actual paragraph text is required to be on the next line and indented four spaces.
Like Custom.paragraph, but parses many styled paragraphs.
Note Parsing ends when there are three consecutive newlines.
Parse a 4-space-indented, unstyled block of text.
It ends after three consecutive newline characters.
Run a parser created with elm/parser where you can parse whatever you'd like. This is actually how the list block is implemented.
I highly recommend using the other Custom parsers if possible as this is the only one that can "break" an elm-markup file.
You're in charge of defining when this parser will stop parsing.
Current conventions:
These conventions may be enforced in the future.
Here's a terrible example.
Custom.parser "bananaTree"
(\inlines ->
-- `inlines` is a parser for styled text which you may or maynot need,
Parser.succeed identity
|. Parser.token " "
|= (Parser.map
-- the result of our parser should be a function that
-- takes a `styling` and a `model` and returns `Element msg`
(\_ styling model ->
Element.el [] (Element.text "bananas"
)
(Parser.token "bananas")
)
|. Parser.token "\n"
)It parses bananas and then says bananas. If you wanted to do exactly this in real life, you would probably use some form of Custom.block.