Add all variation for BonzaiMark

This commit is contained in:
rwxrob 2022-04-05 14:24:36 -04:00
parent 717693ff6f
commit 199a74b181
No known key found for this signature in database
GPG Key ID: 2B9111F33082AE77
3 changed files with 462 additions and 68 deletions

View File

@ -372,11 +372,11 @@ want the specific reasons.
`Z.PrintInWrap(a string)` - shorthand for fmt.Print(Z.InWrap(a string))
`Z.PrintMark(a string)` - shorthand for fmt.Print(Z.Mark(a string))
`
`Z.PrintEmphf(a string, f ...any)` - fmt.Print(Z.Emphf(a string, f ...any))
`Z.PrintWrapf(a string, f ...any)` - fmt.Print(Z.Wrapf(a string, f ...any))
`Z.PrintIndent(a string, f ...any)` - fmt.Print(Z.Indentf(a string, f ...any))
`Z.PrintInWrapf(a string, f ...any)` - fmt.Print(Z.InWrapf(a string, f ...any))
`Z.PrintMarkf(a string, f ...any)` - fmt.Print(Z.Markf(a string, f ...any))
`Z.PrintfEmph(a string, f ...any)` - fmt.Print(Z.Emphf(a string, f ...any))
`Z.PrintfWrap(a string, f ...any)` - fmt.Print(Z.Wrapf(a string, f ...any))
`Z.PrintfIndent(a string, f ...any)` - fmt.Print(Z.Indentf(a string, f ...any))
`Z.PrintfInWrap(a string, f ...any)` - fmt.Print(Z.InWrapf(a string, f ...any))
`Z.PrintfMark(a string, f ...any)` - fmt.Print(Z.Markf(a string, f ...any))
## Acknowledgements

View File

@ -1,6 +1,7 @@
package Z
import (
"fmt"
"regexp"
"strconv"
"unicode"
@ -156,7 +157,7 @@ MAIN:
return blocks
}
// Emph renders BonzaiMark emphasis spans specifically for
// Mark renders BonzaiMark emphasis spans specifically for
// VT100-compatible terminals (which almost all are today):
//
// *Italic*
@ -295,3 +296,73 @@ func Mark(in string) string {
return out
}
// Emphf calls fmt.Sprintf on the string before passing it to Emph.
func Emphf(a string, f ...any) string {
return Emph(fmt.Sprintf(a, f...))
}
// Indentf calls fmt.Sprintf on the string before passing it to Indent.
func Indentf(a string, f ...any) string {
return Indent(fmt.Sprintf(a, f...))
}
// Wrapf calls fmt.Sprintf on the string before passing it to Wrap.
func Wrapf(a string, f ...any) string {
return Wrap(fmt.Sprintf(a, f...))
}
// InWrapf calls fmt.Sprintf on the string before passing it to InWrap.
func InWrapf(a string, f ...any) string {
return InWrap(fmt.Sprintf(a, f...))
}
// Markf calls fmt.Sprintf on the string before passing it to Mark.
func Markf(a string, f ...any) string {
return Mark(fmt.Sprintf(a, f...))
}
// PrintEmph passes string to Emph and prints it.
func PrintEmph(a string) { fmt.Print(Emph(a)) }
// PrintWrap passes string to Wrap and prints it.
func PrintWrap(a string) { fmt.Print(Wrap(a)) }
// PrintIndent passes string to Indent and prints it.
func PrintIndent(a string) { fmt.Print(Indent(a)) }
// PrintInWrap passes string to InWrap and prints it.
func PrintInWrap(a string) { fmt.Print(InWrap(a)) }
// PrintMark passes string to Mark and prints it.
func PrintMark(a string) { fmt.Print(Mark(a)) }
// PrintEmphf calls fmt.Sprintf on the string before passing it to Emph
// and then printing it.
func PrintEmphf(a string, f ...any) {
fmt.Print(Emph(fmt.Sprintf(a, f...)))
}
// PrintWrapf calls fmt.Sprintf on the string before passing it to Wrap
// and then printing it.
func PrintWrapf(a string, f ...any) {
fmt.Print(Wrap(fmt.Sprintf(a, f...)))
}
// PrintIndentf calls fmt.Sprintf on the string before passing it to
// Indent and then printing it.
func PrintIndentf(a string, f ...any) {
fmt.Print(Indent(fmt.Sprintf(a, f...)))
}
// PrintInWrapf calls fmt.Sprintf on the string before passing it to
// InWrap and then printing it.
func PrintInWrapf(a string, f ...any) {
fmt.Print(InWrap(fmt.Sprintf(a, f...)))
}
// PrintMarkf calls fmt.Sprintf on the string before passing it to Mark
// and then printing it.
func PrintMarkf(a string, f ...any) {
fmt.Print(Mark(fmt.Sprintf(a, f...)))
}

View File

@ -13,68 +13,7 @@ func ExampleLines() {
// ["line one" "line two"]
}
func ExampleEmph_basics() {
// Emph observes the rwxrob/term escapes
// (see package documentation for more)
term.Italic = `<italic>`
term.Bold = `<bold>`
term.BoldItalic = `<bolditalic>`
term.Under = `<under>`
term.Reset = `<reset>`
fmt.Println(Z.Emph("*ITALIC*"))
fmt.Println(Z.Emph("**BOLD**"))
fmt.Println(Z.Emph("***BOLDITALIC***"))
fmt.Println(Z.Emph("<UNDER>")) // keeps brackets
// Output:
// <italic>ITALIC<reset>
// <bold>BOLD<reset>
// <bolditalic>BOLDITALIC<reset>
// <<under>UNDER<reset>>
}
func ExampleWrap() {
col := Z.Columns
Z.Columns = 10
fmt.Println(Z.Wrap(`some thing here that is more than 10 characters`))
Z.Columns = col
// Output:
// some thing
// here that
// is more
// than 10
// characters
}
func ExampleIndent() {
indent := Z.IndentBy
col := Z.Columns
Z.Columns = 10
Z.Columns = 10
Z.IndentBy = 4
fmt.Printf("%q", Z.Indent("some\nthat is \n indented"))
Z.IndentBy = indent
Z.Columns = col
// Output:
// " some\n that is \n indented\n"
}
func ExampleInWrap() {
defer func() { Z.IndentBy = Z.IndentBy }()
indent := Z.IndentBy
col := Z.Columns
Z.Columns = 10
Z.IndentBy = 4
fmt.Printf("%q", Z.InWrap("some\nthat is \n indented"))
Z.IndentBy = indent
Z.Columns = col
// Output:
// " some\n that\n is\n indented\n"
}
// --------------------------- start Blocks ---------------------------
func ExampleBlocks_bulleted() {
in := `
@ -159,6 +98,71 @@ func ExampleBlocks_verbatim() {
}
// -------------------------- main BonzaiMark -------------------------
func ExampleEmph_basics() {
// Emph observes the rwxrob/term escapes
// (see package documentation for more)
term.Italic = `<italic>`
term.Bold = `<bold>`
term.BoldItalic = `<bolditalic>`
term.Under = `<under>`
term.Reset = `<reset>`
fmt.Println(Z.Emph("*ITALIC*"))
fmt.Println(Z.Emph("**BOLD**"))
fmt.Println(Z.Emph("***BOLDITALIC***"))
fmt.Println(Z.Emph("<UNDER>")) // keeps brackets
// Output:
// <italic>ITALIC<reset>
// <bold>BOLD<reset>
// <bolditalic>BOLDITALIC<reset>
// <<under>UNDER<reset>>
}
func ExampleWrap() {
col := Z.Columns
Z.Columns = 10
fmt.Println(Z.Wrap(`some thing here that is more than 10 characters`))
Z.Columns = col
// Output:
// some thing
// here that
// is more
// than 10
// characters
}
func ExampleIndent() {
indent := Z.IndentBy
col := Z.Columns
Z.Columns = 10
Z.Columns = 10
Z.IndentBy = 4
fmt.Printf("%q", Z.Indent("some\nthat is \n indented"))
Z.IndentBy = indent
Z.Columns = col
// Output:
// " some\n that is \n indented\n"
}
func ExampleInWrap() {
defer func() { Z.IndentBy = Z.IndentBy }()
indent := Z.IndentBy
col := Z.Columns
Z.Columns = 10
Z.IndentBy = 4
fmt.Printf("%q", Z.InWrap("some\nthat is \n indented"))
Z.IndentBy = indent
Z.Columns = col
// Output:
// " some\n that\n is\n indented\n"
}
func ExampleMark() {
in := `
@ -213,3 +217,322 @@ func ExampleMark() {
// ----------------------
}
// ------------------------ Sprintf variations ------------------------
func ExampleEmphf() {
fmt.Println(Z.Emphf(`some *%v* thing`, "italic"))
// Output:
// some <italic>italic<reset> thing
}
func ExampleWrapf() {
col := Z.Columns
Z.Columns = 3
fmt.Println(Z.Wrapf(`some %v here`, 10))
Z.Columns = col
// Output:
// some
// 10
// here
}
func ExampleIndentf() {
in := Z.IndentBy
Z.IndentBy = 3
fmt.Println(Z.Indentf("-----\nindented by %v here", Z.IndentBy))
Z.IndentBy = in
// Output:
// -----
// indented by 3 here
}
func ExampleInWrapf() {
in := Z.IndentBy
col := Z.Columns
Z.IndentBy = 3
Z.Columns = 10
fmt.Println(
Z.InWrapf("-----\nindented by %v here and wrapped at %v",
Z.IndentBy, Z.Columns,
))
Z.IndentBy = in
Z.Columns = col
// -----
// indented
// by 3
// here
// and
// wrapped
// at 10
}
func ExampleMarkf() {
in := `
Must have *%v* block before verbatim:
Now we can start
a Verbatim
block.
Which can have blank lines, even.
And back to a %v block.
* **foo**
* bar
And a numbered list
1. Something
2. here
That's really it.
`
fmt.Println("----------------------")
fmt.Print(Z.Markf(in, "another", "paragraph"))
fmt.Println("----------------------")
//Output:
// ----------------------
// Must have <italic>another<reset> block before verbatim:
//
// Now we can start
// a Verbatim
// block.
//
// Which can have blank lines, even.
//
// And back to a paragraph block.
//
// * <bold>foo<reset>
// * bar
//
// And a numbered list
//
// 1. Something
// 2. here
//
// That's really it.
//
// ----------------------
}
// ------------------------- Print variations -------------------------
func ExamplePrintEmph_basics() {
// Emph observes the rwxrob/term escapes
// (see package documentation for more)
term.Italic = `<italic>`
term.Bold = `<bold>`
term.BoldItalic = `<bolditalic>`
term.Under = `<under>`
term.Reset = `<reset>`
Z.PrintEmph("*ITALIC*\n")
Z.PrintEmph("**BOLD**\n")
Z.PrintEmph("***BOLDITALIC***\n")
Z.PrintEmph("<UNDER>\n") // keeps brackets
// Output:
// <italic>ITALIC<reset>
// <bold>BOLD<reset>
// <bolditalic>BOLDITALIC<reset>
// <<under>UNDER<reset>>
}
func ExamplePrintWrap() {
col := Z.Columns
Z.Columns = 10
Z.PrintWrap(`some thing here that is more than 10 characters`)
Z.Columns = col
// Output:
// some thing
// here that
// is more
// than 10
// characters
}
func ExamplePrintInWrap() {
defer func() { Z.IndentBy = Z.IndentBy }()
indent := Z.IndentBy
col := Z.Columns
Z.Columns = 10
Z.IndentBy = 4
fmt.Println("-----")
Z.PrintInWrap("some\nthat is \n indented")
Z.IndentBy = indent
Z.Columns = col
// Output:
// -----
// some
// that
// is
// indented
}
func ExamplePrintMark() {
in := `
Must have *another* block before verbatim:
Now we can start
a Verbatim
block.
Which can have blank lines, even.
And back to a paragraph block.
* **foo**
* bar
And a numbered list
1. Something
2. here
That's really it.
`
fmt.Println("----------------------")
Z.PrintMark(in)
fmt.Println("----------------------")
//Output:
// ----------------------
// Must have <italic>another<reset> block before verbatim:
//
// Now we can start
// a Verbatim
// block.
//
// Which can have blank lines, even.
//
// And back to a paragraph block.
//
// * <bold>foo<reset>
// * bar
//
// And a numbered list
//
// 1. Something
// 2. here
//
// That's really it.
//
// ----------------------
}
// --------------------- Print(Sprintf) variations --------------------
func ExamplePrintEmphf() {
Z.PrintEmphf(`some *%v* thing`, "italic")
// Output:
// some <italic>italic<reset> thing
}
func ExamplePrintfWrapf() {
col := Z.Columns
Z.Columns = 3
Z.PrintWrapf(`some %v here`, 10)
Z.Columns = col
// Output:
// some
// 10
// here
}
func ExamplePrintIndentf() {
in := Z.IndentBy
Z.IndentBy = 3
Z.PrintIndentf("-----\nindented by %v here", Z.IndentBy)
Z.IndentBy = in
// Output:
// -----
// indented by 3 here
}
func ExamplePrintInWrapf() {
in := Z.IndentBy
col := Z.Columns
Z.IndentBy = 3
Z.Columns = 10
Z.PrintInWrapf("-----\nindented by %v here and wrapped at %v",
Z.IndentBy, Z.Columns,
)
Z.IndentBy = in
Z.Columns = col
// -----
// indented
// by 3
// here
// and
// wrapped
// at 10
}
func ExamplePrintMarkf() {
in := `
Must have *%v* block before verbatim:
Now we can start
a Verbatim
block.
Which can have blank lines, even.
And back to a %v block.
* **foo**
* bar
And a numbered list
1. Something
2. here
That's really it.
`
fmt.Println("----------------------")
Z.PrintMarkf(in, "another", "paragraph")
fmt.Println("----------------------")
//Output:
// ----------------------
// Must have <italic>another<reset> block before verbatim:
//
// Now we can start
// a Verbatim
// block.
//
// Which can have blank lines, even.
//
// And back to a paragraph block.
//
// * <bold>foo<reset>
// * bar
//
// And a numbered list
//
// 1. Something
// 2. here
//
// That's really it.
//
// ----------------------
}