-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extract all api introduce string package introduce HasInner make Markdown and others context aware and context required deprecate unsafe methods add implicit conversion (still unstable)
- Loading branch information
1 parent
4588821
commit f7a15ce
Showing
30 changed files
with
499 additions
and
264 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,24 @@ | ||
package halotukozak.smark | ||
|
||
def markdown(input: String*): String = input.mkString("\n\n") | ||
import tables.Table | ||
import utils.HasInner | ||
|
||
type MdContent = String | MdElement | Table | ||
opaque type MdUnit = Unit | ||
|
||
private trait MdElement extends HasInner[MdContent]: | ||
private[smark] def eval: String | ||
end MdElement | ||
|
||
private class Markdown extends MdElement: | ||
private[smark] def eval = inner.mkString("\n\n") | ||
|
||
end Markdown | ||
|
||
extension (s: MdContent) | ||
private def eval: String = s match | ||
case s: String => s | ||
case e: MdElement => e.eval | ||
case t: Table => t.eval | ||
|
||
implicit def stringToModifier(s: String)(using m: MdElement): MdUnit = m.add(s) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package halotukozak.smark | ||
|
||
import tables.* | ||
import typography.* | ||
import typography.macros.* | ||
|
||
|
||
private inline def initAndAdd[T <: MdElement](inline q: T)(inline init: T ?=> MdUnit)(using m: MdElement): MdUnit = | ||
init(using q) | ||
m.add(q) | ||
|
||
def markdown(init: MdElement ?=> MdUnit): String = | ||
given m: MdElement = new Markdown | ||
|
||
init(using m) | ||
m.eval | ||
|
||
inline def text[Style <: TextStyle](inline inner: String)(using m: MdElement): MdUnit = m.add(textMacro[Style](inner)) | ||
|
||
inline def emoji[E <: Emoji](using m: MdElement): MdUnit = m.add(emojiMacro[E]) | ||
|
||
inline def quote[AlertType <: Alert : ValueOf](inline init: MdElement ?=> MdUnit)(using m: MdElement): MdUnit = initAndAdd(new typography.Quote[AlertType])(init) | ||
|
||
inline def heading[N <: HeadingLevel : ValueOf](inline init: MdElement ?=> MdUnit)(using m: MdElement): MdUnit = initAndAdd(new typography.Heading[N])(init) | ||
|
||
inline def code[L <: code](inline inner: L)(using m: MdElement): MdUnit = m.add(codeMacro[L](inner)) | ||
|
||
inline def list[Style <: ListStyle](inline elements: String*)(using m: MdElement): MdUnit = m.add(listMacro[Style](elements)) | ||
|
||
inline def taskList(inline points: ((Boolean, String) | String)*)(using m: MdElement): MdUnit = m.add(taskListMacro(points *)) | ||
|
||
inline def hr(using m: MdElement): MdUnit = m.add("***") | ||
|
||
inline def paragraph(inline init: MdElement ?=> MdUnit)(using m: MdElement): MdUnit = initAndAdd(new typography.Paragraph)(init) | ||
|
||
inline def comment(inline init: MdElement ?=> MdUnit)(using m: MdElement): MdUnit = initAndAdd(new typography.Comment)(init) | ||
|
||
inline def link[Title <: String](inline url: String)(using m: MdElement): MdUnit = m.add(linkMacro[Title](url)) | ||
|
||
inline def image[title <: String](inline url: String)(using m: MdElement): MdUnit = m.add(imageMacro[title](url)) | ||
|
||
def table(init: Table ?=> MdUnit)(using m: MdElement): MdUnit = | ||
given t: Table = new Table | ||
|
||
init(using t) | ||
m.add(t) | ||
|
||
def row(init: Row ?=> MdUnit)(using t: Table): MdUnit = | ||
given r: Row = new Row | ||
|
||
init(using r) | ||
t.add(r) | ||
|
||
def header(columns: (Column | String)*)(using t: Table): MdUnit = | ||
t.add { | ||
Header(columns.map { | ||
case c: Column => c | ||
case s: String => Column.None(s) | ||
}) | ||
} | ||
|
||
def cell(init: MdElement ?=> MdUnit)(using r: Row): MdUnit = | ||
r.add { | ||
given c: Cell = new Cell | ||
|
||
init(using c) | ||
c | ||
} | ||
|
||
|
||
package string: | ||
inline def text[Style <: TextStyle](inline inner: String): String = textMacro[Style](inner) | ||
|
||
inline def emoji[E <: Emoji]: String = emojiMacro[E] | ||
|
||
inline def link[Title <: String](inline url: String): String = linkMacro[Title](url) | ||
|
||
inline def image[title <: String](inline url: String): String = imageMacro[title](url) | ||
end string | ||
|
||
|
||
import _root_.scala.language.implicitConversions | ||
|
||
given Conversion[Unit, MdUnit] with | ||
def apply(u: Unit): MdUnit = ().asInstanceOf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
package halotukozak.smark | ||
package typography | ||
|
||
type Alert | ||
type Note <: Alert | ||
type Tip <: Alert | ||
type Important <: Alert | ||
type Warning <: Alert | ||
type Caution <: Alert | ||
type Alert = Note | Tip | Important | Warning | Caution | ||
type Note = "Note" | ||
type Tip = "Tip" | ||
type Important = "Important" | ||
type Warning = "Warning" | ||
type Caution = "Caution" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package halotukozak.smark | ||
package typography | ||
|
||
final class Comment extends MdElement: | ||
override private[smark] def eval: String = | ||
val lines = inner.map(e => e.eval).toSeq | ||
commentMacro(if lines.length == 1 then lines.mkString("\n") else lines.mkString("\n", "\n", "\n")) | ||
|
||
private[smark] inline def commentMacro(inline inner: String): String = s"<!-- $inner -->" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package halotukozak.smark | ||
package typography | ||
|
||
final class Paragraph extends MdElement: | ||
|
||
override private[smark] def eval: String = paragraphMacro(inner.map(e => e.eval).mkString("\n\n")) | ||
|
||
private[smark] inline def paragraphMacro(inline inner: String): String = "\n" + inner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
package halotukozak.smark | ||
package typography | ||
|
||
import typography.macros.quote | ||
import typography.* | ||
import typography.macros.textMacro | ||
|
||
inline def note(inline inner: String*): String = quote[Note](inner *) | ||
inline def tip(inline inner: String*): String = quote[Tip](inner *) | ||
inline def important(inline inner: String*): String = quote[Important](inner *) | ||
inline def warning(inline inner: String*): String = quote[Warning](inner *) | ||
inline def caution(inline inner: String*): String = quote[Caution](inner *) | ||
private[smark] final class Quote[AlertType <: Alert : ValueOf] extends MdElement: | ||
override private[smark] def eval: String = | ||
(s"[!${valueOf[AlertType]}]" +: inner) | ||
.map(e => textMacro[Quoted](e.eval)) | ||
.mkString("\n") | ||
|
||
end Quote |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.