Fix ESC/POS notation parser: '#' only starts a comment as its own token
deploy / deploy (push) Successful in 9s

Stripping from the first '#' anywhere in the line ate content like '#5
Fix thing' (an issue reference) entirely, since it starts with '#' with
no preceding whitespace. Comments now only trigger on a standalone '#'
token (i.e. whitespace on both sides), matching the documented examples.
This commit is contained in:
randy committed 2026-09-13 11:51:36 +02:00
1 parent f09c92f201
commit 790d716d57
1 file changed
+13 -7
+13 -7
View File
@@ -117,17 +117,23 @@ helpers do
# Hello # literal text # Hello # literal text
# LF # LF
# GS k 0x03 12345678 0x00 # GS k 0x03 12345678 0x00
# Each `#...` trailing comment is stripped, then each line's # A trailing comment is only a comment when "#" is its own
# whitespace-separated tokens become either a known control mnemonic, a # whitespace-separated token -- not just stripped from the first "#"
# raw `0xNN` byte, or literal text (CP852-encoded) -- consecutive literal # anywhere in the line, which would mangle literal text like "#5 Fix
# tokens are rejoined with a single space so plain prose still reads # thing" (an issue reference, not a comment). Each remaining token
# correctly, while whitespace around control/byte tokens is dropped since # becomes a known control mnemonic, a raw `0xNN` byte, or literal text
# those are just for human readability, not printer output. # (CP852-encoded) -- consecutive literal tokens are rejoined with a
# single space so plain prose still reads correctly, while whitespace
# around control/byte tokens is dropped since those are just for human
# readability, not printer output.
def parse_escpos_notation(text) def parse_escpos_notation(text)
bytes = "".b bytes = "".b
text.each_line do |line| text.each_line do |line|
prev_was_text = false prev_was_text = false
line.sub(/#.*/, '').split.each do |token| tokens = line.split
comment_at = tokens.index('#')
tokens = tokens[0...comment_at] if comment_at
tokens.each do |token|
if ESCPOS_MNEMONICS.key?(token) if ESCPOS_MNEMONICS.key?(token)
bytes << ESCPOS_MNEMONICS[token] bytes << ESCPOS_MNEMONICS[token]
prev_was_text = false prev_was_text = false