diff --git a/data/static/style.css b/data/static/style.css index 8818029..0cc6787 100644 --- a/data/static/style.css +++ b/data/static/style.css @@ -120,6 +120,16 @@ pre code { padding: 20px; } +.inline-code { + background-color: rgb(38.5714173228, 40.9237007874, 35.6762992126); + color: white; + padding: 5px 10px; + display: inline-block; + margin: 4px; + border-radius: 4px; + font-size: 1rem; +} + .copy-code-container { position: sticky; width: calc(100% - 4px); diff --git a/lib/babycode.lua b/lib/babycode.lua index 2c441c6..e8ea09d 100644 --- a/lib/babycode.lua +++ b/lib/babycode.lua @@ -8,12 +8,19 @@ function babycode.to_html(s, escape_html) -- extract code blocks first and store them as placeholders -- don't want to process bbcode embedded into a code block local code_blocks = {} + local inline_codes = {} s = escape_html(s) local text = s:gsub("%[code%](.-)%[/code%]", function(code) - -- strip leading and trailing newlines, preserve others - local m, _ = code:gsub("^%s*(.-)%s*$", "%1") - table.insert(code_blocks, m) - return "\1CODE:"..#code_blocks.."\1" + local is_inline = code:match("\n") == nil + if is_inline then + table.insert(inline_codes, code) + return "\1ICODE:"..#inline_codes.."\1" + else + -- strip leading and trailing newlines, preserve others + local m, _ = code:gsub("^%s*(.-)%s*$", "%1") + table.insert(code_blocks, m) + return "\1CODE:"..#code_blocks.."\1" + end end) -- replace `[url=https://example.com]Example[/url] tags @@ -51,6 +58,11 @@ function babycode.to_html(s, escape_html) local button = (""):format(code) return "
" .. button .. ""..code.."
" end) + + text = text:gsub("\1ICODE:(%d+)\1", function (n) + local code = inline_codes[tonumber(n)] + return "" .. code .. "" + end) return text end diff --git a/sass/style.scss b/sass/style.scss index 3f6b71a..1faf595 100644 --- a/sass/style.scss +++ b/sass/style.scss @@ -156,6 +156,16 @@ pre code { padding: 20px; } +.inline-code { + background-color: $verydark; + color: white; + padding: 5px 10px; + display: inline-block; + margin: 4px; + border-radius: 4px; + font-size: 1rem; +} + .copy-code-container { position: sticky; // width: 100%; diff --git a/views/common/bbcode_help.etlua b/views/common/bbcode_help.etlua index 5c9da65..b3bc808 100644 --- a/views/common/bbcode_help.etlua +++ b/views/common/bbcode_help.etlua @@ -6,6 +6,16 @@
  • [s]strikethrough[/s]
  • [url=https://example.com]labeled URL[/url]
  • [url]https://unlabeled-url.example.com[/url]
  • -
  • [code]code block[/code]
  • +
  • + [code]with
    line breaks[/code] will produce a code block: +
    + Show code block example +
    with
    +line breaks
    +
    +
  • +
  • [code]with no line breaks[/code]
  • +
  • --- will create a horizontal rule for separating content