diff --git a/Makefile b/Makefile index 3ab90aa2..56cb45b3 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,7 @@ export external="--external:*.png" "--external:*.jpg" "--external:*.gif" export external+="--external:/assets/css/ui/deleted.svg" export external+="--external:/assets/css/MadokaRunes-2.0.ttf" export external+="--external:/assets/css/glass-bg.avif" +export external+="--external:/assets/css/Saitamaar-Regular.woff2" export tsconf=--tsconfig=./client/tsconfig.json --target=es2024 export tsconf+=--minify-whitespace --minify-syntax diff --git a/client/common/index.ts b/client/common/index.ts index 55217cab..3824ef0b 100644 --- a/client/common/index.ts +++ b/client/common/index.ts @@ -69,6 +69,7 @@ export type TextState = { spoiler: boolean quote: boolean code: boolean + aa: boolean bold: boolean italic: boolean red: boolean diff --git a/client/posts/model.ts b/client/posts/model.ts index c315da4e..75f2480d 100644 --- a/client/posts/model.ts +++ b/client/posts/model.ts @@ -62,6 +62,7 @@ export class Post extends Model implements PostData { spoiler: false, quote: false, code: false, + aa: false, bold: false, italic: false, red: false, @@ -109,6 +110,7 @@ export class Post extends Model implements PostData { const needReparse = char === "\n" || !this.editing || this.state.code + || this.state.aa || endsWithTag(this.body) if (needReparse) { this.view.reparseBody() @@ -122,6 +124,7 @@ export class Post extends Model implements PostData { const needReparse = this.body[this.body.length - 1] === "\n" || !this.editing || this.state.code + || this.state.aa || endsWithTag(this.body) this.body = this.body.slice(0, -1) if (needReparse) { @@ -310,6 +313,8 @@ function endsWithTag(body: string): boolean { return sl === "^" case "p": return sl === "^" + case "a": + return sl === "^" } return false } diff --git a/client/posts/posting/model.ts b/client/posts/posting/model.ts index 7234b6c5..91f487b5 100644 --- a/client/posts/posting/model.ts +++ b/client/posts/posting/model.ts @@ -38,6 +38,7 @@ export default class FormModel extends Post { spoiler: false, quote: false, code: false, + aa: false, bold: false, italic: false, red: false, diff --git a/client/posts/render/body.ts b/client/posts/render/body.ts index 87e3e9dc..bdc2b980 100644 --- a/client/posts/render/body.ts +++ b/client/posts/render/body.ts @@ -21,6 +21,7 @@ export default function renderBody(data: PostData): string { spoiler: false, quote: false, code: false, + aa: false, bold: false, italic: false, red: false, @@ -47,7 +48,7 @@ export default function renderBody(data: PostData): string { } state.successive_newlines = 0 - if (l[0] === ">") { + if (l[0] === ">" && !state.aa) { state.quote = true html += "" } @@ -159,7 +160,7 @@ function parseTerminatedLine(line: string, data: PostData): string { parseFragment(frag, data)) } -// Detect code tags +// Detect code and Shift-JIS ASCII art tags function parseCode( frag: string, state: TextState, @@ -167,11 +168,31 @@ function parseCode( ): string { let html = "" while (true) { - const i = frag.indexOf("``") + let i: number + let isAA = false + if (state.code) { + i = frag.indexOf("``") + } else if (state.aa) { + i = frag.indexOf("^a") + isAA = true + } else { + const iCode = frag.indexOf("``") + const iAA = frag.indexOf("^a") + if (iAA !== -1 && (iCode === -1 || iAA < iCode)) { + i = iAA + isAA = true + } else { + i = iCode + } + } if (i !== -1) { html += formatCode(frag.slice(0, i), state, fn) frag = frag.substring(i + 2) - state.code = !state.code + if (isAA) { + state.aa = !state.aa + } else { + state.code = !state.code + } } else { html += formatCode(frag, state, fn) break @@ -193,6 +214,8 @@ function formatCode( frag = frag.slice(1) } html += highlightSyntax(frag) + } else if (state.aa) { + html += `${escape(frag)}` } else { html += parseFmt(frag, state, fn, 0) } diff --git a/config/config.go b/config/config.go index 0e1c057a..66220092 100644 --- a/config/config.go +++ b/config/config.go @@ -101,6 +101,7 @@ WAV, MIDI, PDF, EPUB, ZIP, 7Z, TAR.GZ, TAR.XZ, RAR, CBZ, CBR, SWF. ~~ for italics ` + "``" + ` for programming code highlights ^r, ^b, ^y or ^p for colored text + ^a for Shift-JIS ASCII art
Hash commands: #d100 #2d100 - Roll dice #flip - Coin flip diff --git a/css/posts.css b/css/posts.css index 51e60cd5..cbe18cf0 100644 --- a/css/posts.css +++ b/css/posts.css @@ -200,11 +200,31 @@ blockquote { } } +@font-face { + font-family: Saitamaar; + src: url("/assets/css/Saitamaar-Regular.woff2") format("woff2"); + font-weight: normal; + font-style: normal; + font-display: swap; +} + .code-tag { margin: 0; white-space: pre-wrap; } +.aa { + font-family: Saitamaar, "MS Pゴシック", "MS PGothic", "Mona", sans-serif; + font-size: 16px; + line-height: 18px; + white-space: pre; +} + +blockquote:has(.aa) { + padding: 2px; + overflow-x: auto; +} + .mawaru { animation: spin 0.25s linear 200; display: inline-block; diff --git a/templates/body.go b/templates/body.go index 15e02b10..234b2ebd 100644 --- a/templates/body.go +++ b/templates/body.go @@ -76,9 +76,9 @@ var ( type bodyContext struct { index bool // Rendered for an index page state struct { // Body parser state - spoiler, quote, code, bold, italic, red, blue, yellow, purple, pyu bool - successiveNewlines uint - iDice int + spoiler, quote, code, aa, bold, italic, red, blue, yellow, purple, pyu bool + successiveNewlines uint + iDice int } common.Post OP uint64 @@ -124,7 +124,7 @@ func streambody( } c.state.successiveNewlines = 0 - if l[0] == '>' { + if l[0] == '>' && !c.state.aa { c.string("") c.state.quote = true } @@ -246,14 +246,35 @@ func (c *bodyContext) parseTerminatedLine(line string) { c.parseCode(line, (*c).parseFragment) } -// Detect code tags +// Detect code and Shift-JIS ASCII art tags func (c *bodyContext) parseCode(frag string, fn func(string)) { for { - i := strings.Index(frag, "``") + var i int + var isAA bool + switch { + case c.state.code: + i = strings.Index(frag, "``") + case c.state.aa: + i = strings.Index(frag, "^a") + isAA = true + default: + iCode := strings.Index(frag, "``") + iAA := strings.Index(frag, "^a") + if iAA != -1 && (iCode == -1 || iAA < iCode) { + i = iAA + isAA = true + } else { + i = iCode + } + } if i != -1 { c.formatCode(frag[:i], fn) frag = frag[i+2:] - c.state.code = !c.state.code + if isAA { + c.state.aa = !c.state.aa + } else { + c.state.code = !c.state.code + } } else { c.formatCode(frag, fn) break @@ -262,14 +283,19 @@ func (c *bodyContext) parseCode(frag string, fn func(string)) { } func (c *bodyContext) formatCode(frag string, fn func(string)) { - if c.state.code { + switch { + case c.state.code: // Strip quotes for len(frag) != 0 && frag[0] == '>' { c.string(`>`) frag = frag[1:] } c.N().Z(highlightSyntax(frag)) - } else { + case c.state.aa: + c.string(``) + c.escape(frag) + c.string(``) + default: c.parseFmt(frag, 0) } } diff --git a/templates/body_test.go b/templates/body_test.go index a0f155c7..27b33cb5 100644 --- a/templates/body_test.go +++ b/templates/body_test.go @@ -77,6 +77,11 @@ func TestRenderBody(t *testing.T) { in: "foo** bar@@b~~a@@z^re^r^br^b**h~~", out: `foo barbazerh`, }, + { + name: "ascii art", + in: "foo ^a\n ∧_∧\n>``**^a bar", + out: "foo
 ∧_∧
>``** bar", + }, { name: "trailing empty open line", in: "foo\n",