From 1f0e043f48b8261563d10f8d7249a78290075f30 Mon Sep 17 00:00:00 2001 From: Alex Karle Date: Mon, 20 Dec 2021 00:54:03 -0500 Subject: [PATCH] Fix inline formatting at beginning of paragraph Paragraphs start usually when a non special character is entered in the NONE state. Previous to this change, they were not starting until that non-special character, meaning lines starting with formatting would have a strange skew:

italics

This patch encapsulates the "start a paragraph if it's NONE" and triggers it for all inline formatting as well as non-special chars --- blag.c | 22 ++++++++++++---------- test/big.html | 12 ++++++++++++ test/big.txt | 6 ++++++ 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/blag.c b/blag.c index 37e8a88..baab51b 100644 --- a/blag.c +++ b/blag.c @@ -65,6 +65,13 @@ int endlist(state *s) { return --s->listdepth; } +void maybe_startp(state *s) { + /* All inline types should start the paragraph if no other major type present*/ + if (s->in == NONE) { + s->in = PARAGRAPH; + printf("

\n"); + } +} void handle_lf(state *s) { s->indent = 0; @@ -188,6 +195,7 @@ int parse() { break; case '`': if (s.in_link != LINK_URL_PARSE && s.in != CODE) { + maybe_startp(&s); if (s.in_code) { printf(""); s.in_code = 0; @@ -201,6 +209,7 @@ int parse() { break; case '*': if (!s.in_code && s.in_link != LINK_URL_PARSE && s.in != CODE) { + maybe_startp(&s); if (s.in_bold) { printf(""); s.in_bold = 0; @@ -214,6 +223,7 @@ int parse() { break; case '_': if (!s.in_code && s.in_link != LINK_URL_PARSE && s.in != CODE) { + maybe_startp(&s); if (s.in_ital) { printf(""); s.in_ital = 0; @@ -238,11 +248,7 @@ int parse() { break; case '[': if (s.in_link == NONE && !s.in_code) { - if (s.in == NONE) { - /* Assume this is a new paragraph */ - s.in = PARAGRAPH; - printf("

\n"); - } + maybe_startp(&s); s.in_link = LINK_URL_PARSE; s.lnkidx = 0; printf(" assume new

*/ - s.in = PARAGRAPH; - printf("

\n"); - } + maybe_startp(&s); putesc(c); break; } diff --git a/test/big.html b/test/big.html index 041ac2f..fcd2182 100644 --- a/test/big.html +++ b/test/big.html @@ -4,6 +4,18 @@ This is an example blag file!

+

+This should be emphasized within a paragraph +

+ +

+As should this bold +

+ +

+and code! +

+

Sub Header 2

Woah a third header?

diff --git a/test/big.txt b/test/big.txt index bb4cb28..6fcbec9 100644 --- a/test/big.txt +++ b/test/big.txt @@ -2,6 +2,12 @@ This is an example blag file! +_This should be emphasized within a paragraph_ + +*As should this bold* + +`and code!` + ## Sub Header 2 ### Woah a third header? -- libgit2 1.1.1