From d622d767a0fe0c764a95b34f6f5726554eb9d7b4 Mon Sep 17 00:00:00 2001 From: Jonathan Bernard Date: Wed, 21 Jun 2023 06:11:00 -0500 Subject: [PATCH] Better line match to avoid cutting off verses that contain line breaks. --- esv_api.nimble | 2 +- src/esv_api.nim | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/esv_api.nimble b/esv_api.nimble index 3ff7435..954c66f 100644 --- a/esv_api.nimble +++ b/esv_api.nimble @@ -1,6 +1,6 @@ # Package -version = "0.2.1" +version = "0.2.2" author = "Jonathan Bernard" description = "Simple Nim CLI wrapper around the ESV API (api.esv.org)" license = "MIT" diff --git a/src/esv_api.nim b/src/esv_api.nim index 614b507..f0301b1 100644 --- a/src/esv_api.nim +++ b/src/esv_api.nim @@ -7,15 +7,15 @@ import std/[httpclient, json, logging, os, re, strutils, uri, wordwrap] import cliutils, docopt, zero_functional proc formatMarkdown(raw: string): string = - let rawLines = raw.splitLines --> map(it.strip) - let wrapped = (rawLines --> - filter(not isEmptyOrWhitespace(it.strip) and match(it, re"^\[\d+\].*")). - map(it.multiReplace([(re"\((\d+)\)", ""), (re"\[(\d+)\]", "**$1**")])). + let rawLines = raw.splitLines + let wrapped = (raw.splitLines --> + filter(match(it, re"^\s+(\[\d+\]|\w).*")). + map(it.strip.multiReplace([(re"\((\d+)\)", ""), (re"\[(\d+)\]", "**$1**")])). map(wrapWords(it, maxLineWidth = 74, newLine = "\p"))). join("\p") result = (wrapped.splitLines --> map("> " & it)).join("\p") & - "\p>\p> -- *" & rawLines[0] & " (ESV)*" + "\p>\p> -- *" & rawLines[0].strip & " (ESV)*" when isMainModule: const USAGE = """Usage: @@ -44,7 +44,7 @@ Options: try: # Parse arguments - let args = docopt(USAGE, version = "0.2.1") + let args = docopt(USAGE, version = "0.2.2") if args["--debug"]: consoleLogger.levelThreshold = lvlDebug