From 1c951b5ffb3c87b401b81d791651e297b0b08790 Mon Sep 17 00:00:00 2001 From: Delanii <46751732+Delanii@users.noreply.github.com> Date: Tue, 13 Oct 2020 10:40:10 +0200 Subject: [PATCH 01/37] Create sample.md --- nonbreakablespace/sample.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 nonbreakablespace/sample.md diff --git a/nonbreakablespace/sample.md b/nonbreakablespace/sample.md new file mode 100644 index 00000000..7787278c --- /dev/null +++ b/nonbreakablespace/sample.md @@ -0,0 +1,24 @@ +# Tests + +## Basic test + +a test i test k test o test s test u test v test z test A test I test K test O test S test U test V test Z test -- test – test + +## Test with numbers + +Test 19 test "19" test + +## Test of double prefixes. + +A i test, i v test, a k test, a v test. + +## Test of block code + +``` +a = 5 +k = "test" +``` + +## Test of inline code + +Test `a = 5` test From ed6a50a84235c2349a0cb025c4c4bdb142046ad0 Mon Sep 17 00:00:00 2001 From: Delanii <46751732+Delanii@users.noreply.github.com> Date: Tue, 13 Oct 2020 10:40:57 +0200 Subject: [PATCH 02/37] Add files via upload --- nonbreakablespace/README.md | 16 +++ nonbreakablespace/expected.html | 12 ++ nonbreakablespace/nonbreakablespace.lua | 163 ++++++++++++++++++++++++ 3 files changed, 191 insertions(+) create mode 100644 nonbreakablespace/README.md create mode 100644 nonbreakablespace/expected.html create mode 100644 nonbreakablespace/nonbreakablespace.lua diff --git a/nonbreakablespace/README.md b/nonbreakablespace/README.md new file mode 100644 index 00000000..4117405f --- /dev/null +++ b/nonbreakablespace/README.md @@ -0,0 +1,16 @@ +# Non-breakable space filter + +This filter replaces regular spaces with non-breakable spaces according to predefined conditions. Currently, this filter replaces regular spaces with unbreakable ones after one-letter words (prefixes and conjunctions): 'a', 'i', 'k', 'o', 's', 'u', 'v', 'z'; and theyre uppercase variant. Also inserts non-breakable spaces in front of en-dashes and in front of numbers. Some extra effort is taken in detecting these patterns in *not-fully* parsed strings (for example, if this filter is used after some macro replacing filter). + +In this regard this filter functions similarly like TeX `vlna` preprocessor or LuaTeX `luavlna` package. + +The default settings are conformant to Czech typography rules, but these can be changed easily by user customization in filter file `nonbreakablespace.lua` by changing contents of `prefixes` or `dashes` tables. + +Currently supported formats are: + +* LaTeX a ConTeXt +* Open Office Document +* MS Word +* HTML + +**NOTE**: Using this filter increases strain on line-breaking patterns. When possible, consider allowing hyphenation. \ No newline at end of file diff --git a/nonbreakablespace/expected.html b/nonbreakablespace/expected.html new file mode 100644 index 00000000..c72bef16 --- /dev/null +++ b/nonbreakablespace/expected.html @@ -0,0 +1,12 @@ +

Tests

+

Basic test

+

a test i test k test o test s test u test v test z test A test I test K test O test S test U test V test Z test – test – test

+

Test with numbers

+

Test 19 test “19” test

+

Test of double prefixes.

+

A i test, i v test, a k test, a v test.

+

Test of block code

+
a = 5
+k = "test"
+

Test of inline code

+

Test a = 5 test

diff --git a/nonbreakablespace/nonbreakablespace.lua b/nonbreakablespace/nonbreakablespace.lua new file mode 100644 index 00000000..3fb7e873 --- /dev/null +++ b/nonbreakablespace/nonbreakablespace.lua @@ -0,0 +1,163 @@ +--[[ +Indexed table of one-letter prefixes, after which should be inserted '\160'. +Verbose, but can be changed per user requirements. +--]] + +local prefixes = { + 'a', + 'i', + 'k', + 'o', + 's', + 'u', + 'v', + 'z', + 'A', + 'I', + 'K', + 'O', + 'S', + 'U', + 'V', + 'Z' +} + +--[[ +Some languages (czech among them) require nonbreakable space *before* long dash +--]] + +local dashes = { + '--', + '–' +} + +--[[ +Table of replacement elements +--]] + +local nonbreakablespaces = { + html = ' ', + latex = '~', + context = '~' +} + +--[[ +Function responsible for searching for one-letter prefixes, after which is +inserted non-breakable space. Function is short-circuited, that means: + +* If it finds match with `prefix` in `prefixes` table, then it returns `true`. +* Otherwise, after the iteration is finished, returns `false` (prefix wasnt +found). +--]] + +function find_one_letter_prefix(my_string) + for index, prefix in ipairs(prefixes) do + if my_string == prefix then + return true + end + end + return false +end + +--[[ +Function responsible for searching for dashes, before whose is inserted +non-breakable space. Function is short-circuited, that means: + +* If it finds match with `dash` in `dashes` table, then it returns `true`. +* Otherwise, after the iteration is finished, returns `false` (dash wasnt +found). +--]] + +function find_dashes(my_dash) + for index, dash in ipairs(dashes) do + if my_dash == dash then + return true + end + end + return false +end + +--[[ +Function to determine Space element replacement for non-breakable space according to output format +--]] + +function insert_nonbreakable_space(format) + if format == 'html' then + return pandoc.RawInline('html', nonbreakablespaces.html) + elseif format:match 'latex' then + return pandoc.RawInline('tex',nonbreakablespaces.latex) + elseif format:match 'context' then + return pandoc.RawInline('tex',nonbreakablespaces.latex) + else + --fallback to inserting non-breakable space unicode symbol + return pandoc.Str '\u{a0}' + end +end + +--[[ +Core filter function: + +* It iterates over all inline elements in block +* If it finds Space element, uses previously defined functions to find +`prefixes` or `dashes` +* Replaces Space element with `Str '\u{a0}'`, which is non-breakable space +representation +* Returns modified list of inlines +--]] + +function Inlines (inlines) + + --variable holding replacement value for the non-breakable space + local insert = insert_nonbreakable_space(FORMAT) + + for i = 1, #inlines do + if inlines[i].t == 'Space' then + + -- Check for one-letter prefixes in Str before Space + + if inlines[i - 1].t == 'Str' then + local one_letter_prefix = find_one_letter_prefix(inlines[i - 1].text) + if one_letter_prefix == true then +-- inlines[i] = pandoc.Str '\xc2\xa0' -- Both work + inlines[i] = insert + end + end + + -- Check for dashes in Str after Space + + if inlines[i + 1].t == 'Str' then + local dash = find_dashes(inlines[i + 1].text) + if dash == true then + inlines[i] = insert + end + end + + -- Check for not fully parsed Str elements - Those might be products of + -- other filters, that were executed before this one + + if inlines[i + 1].t == 'Str' then + if string.match(inlines[i + 1].text, '%.*%s*[„]?%d+[“]?%s*%.*') then + inlines[i] = insert + end + end + + end + + --[[ + Check for Str containing sequence " prefix ", which might occur in case of + preceding filter creates it in one Str element. Also check, if quotation + mark is present introduced by "quotation.lua" filter + --]] + + if inlines[i].t == 'Str' then + for index, prefix in ipairs(prefixes) do + if string.match(inlines[i].text, '%.*%s+[„]?' .. prefix .. '[“]?%s+%.*') then + front, detection, replacement, back = string.match(inlines[i].c, '(%.*)(%s+[„]?' .. prefix .. '[“]?)(%s+)(%.*)') + inlines[i].text = front .. detection .. insert .. back + end + end + end + + end + return inlines +end \ No newline at end of file From dd2f12ec54b806825878450b9d4bba130854e07b Mon Sep 17 00:00:00 2001 From: Delanii <46751732+Delanii@users.noreply.github.com> Date: Tue, 13 Oct 2020 13:57:12 +0200 Subject: [PATCH 03/37] Add files via upload --- nonbreakablespace/makefile | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 nonbreakablespace/makefile diff --git a/nonbreakablespace/makefile b/nonbreakablespace/makefile new file mode 100644 index 00000000..09ca064b --- /dev/null +++ b/nonbreakablespace/makefile @@ -0,0 +1,6 @@ +DIFF ?= diff --strip-trailing-cr -u + +test: + @pandoc --lua-filter=nonbreakablespace.lua sample.md | $(DIFF) expected.html - + +.PHONY: test \ No newline at end of file From 36c91bfb10551ac80da66be6e95af9b2587113fe Mon Sep 17 00:00:00 2001 From: Delanii <46751732+Delanii@users.noreply.github.com> Date: Fri, 6 Nov 2020 21:23:10 +0100 Subject: [PATCH 04/37] Update README.md Updated to have max 80 chars per line. --- nonbreakablespace/README.md | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/nonbreakablespace/README.md b/nonbreakablespace/README.md index 4117405f..c9c81bf4 100644 --- a/nonbreakablespace/README.md +++ b/nonbreakablespace/README.md @@ -1,10 +1,20 @@ # Non-breakable space filter -This filter replaces regular spaces with non-breakable spaces according to predefined conditions. Currently, this filter replaces regular spaces with unbreakable ones after one-letter words (prefixes and conjunctions): 'a', 'i', 'k', 'o', 's', 'u', 'v', 'z'; and theyre uppercase variant. Also inserts non-breakable spaces in front of en-dashes and in front of numbers. Some extra effort is taken in detecting these patterns in *not-fully* parsed strings (for example, if this filter is used after some macro replacing filter). +This filter replaces regular spaces with non-breakable spaces according to +predefined conditions. Currently, this filter replaces regular spaces with +unbreakable ones after one-letter words (prefixes and conjunctions): +'a', 'i', 'k', 'o', 's', 'u', 'v', 'z'; and theyre uppercase variant. Also +inserts non-breakable spaces in front of en-dashes and in front of numbers. +Some extra effort is taken in detecting these patterns in *not-fully* parsed +strings (for example, if this filter is used after some macro replacing +filter). -In this regard this filter functions similarly like TeX `vlna` preprocessor or LuaTeX `luavlna` package. +In this regard this filter functions similarly like TeX `vlna` preprocessor +or LuaTeX `luavlna` package. -The default settings are conformant to Czech typography rules, but these can be changed easily by user customization in filter file `nonbreakablespace.lua` by changing contents of `prefixes` or `dashes` tables. +The default settings are conformant to Czech typography rules, but these can +be changed easily by user customization in filter file `nonbreakablespace.lua` +by changing contents of `prefixes` or `dashes` tables. Currently supported formats are: @@ -13,4 +23,5 @@ Currently supported formats are: * MS Word * HTML -**NOTE**: Using this filter increases strain on line-breaking patterns. When possible, consider allowing hyphenation. \ No newline at end of file +**NOTE**: Using this filter increases strain on line-breaking patterns. Whenever +possible, consider allowing hyphenation. From 7df6f7c62819325adcb578df723eb5fc509110f9 Mon Sep 17 00:00:00 2001 From: Delanii <46751732+Delanii@users.noreply.github.com> Date: Fri, 6 Nov 2020 21:25:09 +0100 Subject: [PATCH 05/37] Rename sample.md to sampleCZ.md Renamed to `sampleCZ` to allow testing of czech language setting. --- nonbreakablespace/{sample.md => sampleCZ.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename nonbreakablespace/{sample.md => sampleCZ.md} (100%) diff --git a/nonbreakablespace/sample.md b/nonbreakablespace/sampleCZ.md similarity index 100% rename from nonbreakablespace/sample.md rename to nonbreakablespace/sampleCZ.md From 64bf9689f29e3212e4b15c4915960e4a41544c60 Mon Sep 17 00:00:00 2001 From: Delanii <46751732+Delanii@users.noreply.github.com> Date: Fri, 6 Nov 2020 21:26:10 +0100 Subject: [PATCH 06/37] Add files via upload Another sample for english language testing. --- nonbreakablespace/sampleEN.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 nonbreakablespace/sampleEN.md diff --git a/nonbreakablespace/sampleEN.md b/nonbreakablespace/sampleEN.md new file mode 100644 index 00000000..2184cd2f --- /dev/null +++ b/nonbreakablespace/sampleEN.md @@ -0,0 +1,28 @@ +--- +lang: cs +--- + +# Tests + +## Basic test + +a test i test A test I test the test The test -- test – test + +## Test with numbers + +Test 19 test "19" test + +## Test of double prefixes. + +A i test, i v test, a k test, a v test. + +## Test of block code + +``` +a = 5 +k = "test" +``` + +## Test of inline code + +Test `a = 5` test From e1678992366dd09606e3e53b71739222e6fa8f47 Mon Sep 17 00:00:00 2001 From: Delanii <46751732+Delanii@users.noreply.github.com> Date: Fri, 6 Nov 2020 21:27:21 +0100 Subject: [PATCH 07/37] Rename expected.html to expectedCZ.html Expected result from compilation of `sampleCZ.md`. Just renamed. --- nonbreakablespace/{expected.html => expectedCZ.html} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename nonbreakablespace/{expected.html => expectedCZ.html} (100%) diff --git a/nonbreakablespace/expected.html b/nonbreakablespace/expectedCZ.html similarity index 100% rename from nonbreakablespace/expected.html rename to nonbreakablespace/expectedCZ.html From 5e829a0c835d6a35c6ad7f5a8fd225d4ddbf4c80 Mon Sep 17 00:00:00 2001 From: Delanii <46751732+Delanii@users.noreply.github.com> Date: Fri, 6 Nov 2020 21:39:20 +0100 Subject: [PATCH 08/37] Update nonbreakablespace.lua Updated to read `lang` variable setting with default value for english, also with fallback to english if `lang` is not specified. Also added english `prefixes`. --- nonbreakablespace/nonbreakablespace.lua | 43 +++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/nonbreakablespace/nonbreakablespace.lua b/nonbreakablespace/nonbreakablespace.lua index 3fb7e873..fa84180a 100644 --- a/nonbreakablespace/nonbreakablespace.lua +++ b/nonbreakablespace/nonbreakablespace.lua @@ -1,8 +1,21 @@ +local utils = require 'pandoc.utils' +local stringify = utils.stringify + --[[ Indexed table of one-letter prefixes, after which should be inserted '\160'. Verbose, but can be changed per user requirements. --]] +local prefixes = {} + +local prefixesEN = { + 'I', + 'a', + 'A', + 'the', + 'The' +} + local prefixes = { 'a', 'i', @@ -22,6 +35,24 @@ local prefixes = { 'Z' } +-- Set `prefixes` according to `lang` metadata value +function Meta(meta) + if meta.lang then + langSet = stringify(meta.lang) + + if langSet == 'cs' then + prefixes = prefixesCZ + else + prefixes = prefixesEN --default to english prefixes + end + + else + prefixes = prefixesEN --default to english prefixes + end + + return prefixes +end + --[[ Some languages (czech among them) require nonbreakable space *before* long dash --]] @@ -152,7 +183,9 @@ function Inlines (inlines) if inlines[i].t == 'Str' then for index, prefix in ipairs(prefixes) do if string.match(inlines[i].text, '%.*%s+[„]?' .. prefix .. '[“]?%s+%.*') then - front, detection, replacement, back = string.match(inlines[i].c, '(%.*)(%s+[„]?' .. prefix .. '[“]?)(%s+)(%.*)') + front, detection, replacement, back = string.match(inlines[i].c, + '(%.*)(%s+[„]?' .. prefix .. '[“]?)(%s+)(%.*)') + inlines[i].text = front .. detection .. insert .. back end end @@ -160,4 +193,10 @@ function Inlines (inlines) end return inlines -end \ No newline at end of file +end + +-- This should change the order of running functions: Meta - Inlines - rest ... +return { + {Meta = Meta}, + {Inlines = Inlines}, +} From 6a62c1658dd43021fa40f446309965998379771e Mon Sep 17 00:00:00 2001 From: Delanii <46751732+Delanii@users.noreply.github.com> Date: Fri, 6 Nov 2020 21:39:54 +0100 Subject: [PATCH 09/37] Rename nonbreakablespace.lua to pandocVlna.lua --- nonbreakablespace/{nonbreakablespace.lua => pandocVlna.lua} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename nonbreakablespace/{nonbreakablespace.lua => pandocVlna.lua} (100%) diff --git a/nonbreakablespace/nonbreakablespace.lua b/nonbreakablespace/pandocVlna.lua similarity index 100% rename from nonbreakablespace/nonbreakablespace.lua rename to nonbreakablespace/pandocVlna.lua From 6a8bc4f33ab04650e25355139d3e54f4ab6eb64b Mon Sep 17 00:00:00 2001 From: Delanii <46751732+Delanii@users.noreply.github.com> Date: Fri, 6 Nov 2020 21:45:31 +0100 Subject: [PATCH 10/37] Delete expectedCZ.html --- nonbreakablespace/expectedCZ.html | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 nonbreakablespace/expectedCZ.html diff --git a/nonbreakablespace/expectedCZ.html b/nonbreakablespace/expectedCZ.html deleted file mode 100644 index c72bef16..00000000 --- a/nonbreakablespace/expectedCZ.html +++ /dev/null @@ -1,12 +0,0 @@ -

Tests

-

Basic test

-

a test i test k test o test s test u test v test z test A test I test K test O test S test U test V test Z test – test – test

-

Test with numbers

-

Test 19 test “19” test

-

Test of double prefixes.

-

A i test, i v test, a k test, a v test.

-

Test of block code

-
a = 5
-k = "test"
-

Test of inline code

-

Test a = 5 test

From d0bc724a66c939d5f315c154fcf1310c0241b2ec Mon Sep 17 00:00:00 2001 From: Delanii <46751732+Delanii@users.noreply.github.com> Date: Fri, 6 Nov 2020 21:46:15 +0100 Subject: [PATCH 11/37] Add files via upload New file for testing after latest filter update. --- nonbreakablespace/expectedCZ.html | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 nonbreakablespace/expectedCZ.html diff --git a/nonbreakablespace/expectedCZ.html b/nonbreakablespace/expectedCZ.html new file mode 100644 index 00000000..1b641ccf --- /dev/null +++ b/nonbreakablespace/expectedCZ.html @@ -0,0 +1,12 @@ +

Tests

+

Basic test

+

a test i test k test o test s test u test v test z test A test I test K test O test S test U test V test Z test – test – test

+

Test with numbers

+

Test 19 test “19” test

+

Test of double prefixes.

+

A i test, i v test, a k test, a v test.

+

Test of block code

+
a = 5
+k = "test"
+

Test of inline code

+

Test a = 5 test

From feec60289004fcba32094f09a58b27ca3d76c140 Mon Sep 17 00:00:00 2001 From: Delanii <46751732+Delanii@users.noreply.github.com> Date: Fri, 6 Nov 2020 21:48:02 +0100 Subject: [PATCH 12/37] Update sampleCZ.md Added explicit `lang` setting. --- nonbreakablespace/sampleCZ.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nonbreakablespace/sampleCZ.md b/nonbreakablespace/sampleCZ.md index 7787278c..cb673095 100644 --- a/nonbreakablespace/sampleCZ.md +++ b/nonbreakablespace/sampleCZ.md @@ -1,3 +1,7 @@ +--- +lang: cs +--- + # Tests ## Basic test From 0cca88ce2c3a8e3885c9451aec828e0d5d1c979e Mon Sep 17 00:00:00 2001 From: Delanii <46751732+Delanii@users.noreply.github.com> Date: Fri, 6 Nov 2020 21:50:33 +0100 Subject: [PATCH 13/37] Add files via upload Added test result for english `lang` setting. --- nonbreakablespace/expectedEN.html | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 nonbreakablespace/expectedEN.html diff --git a/nonbreakablespace/expectedEN.html b/nonbreakablespace/expectedEN.html new file mode 100644 index 00000000..c1f2c504 --- /dev/null +++ b/nonbreakablespace/expectedEN.html @@ -0,0 +1,12 @@ +

Tests

+

Basic test

+

a test i test A test I test the test The test – test – test

+

Test with numbers

+

Test 19 test “19” test

+

Test of double prefixes.

+

A i test, i v test, a k test, a v test.

+

Test of block code

+
a = 5
+k = "test"
+

Test of inline code

+

Test a = 5 test

From ea8e13a6f47bfd72d3cdfd11f9ffe18e02adc6a9 Mon Sep 17 00:00:00 2001 From: Delanii <46751732+Delanii@users.noreply.github.com> Date: Fri, 6 Nov 2020 21:53:53 +0100 Subject: [PATCH 14/37] Update makefile Added test for english `lang` setting, renamed filter file. --- nonbreakablespace/makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nonbreakablespace/makefile b/nonbreakablespace/makefile index 09ca064b..3f634b1c 100644 --- a/nonbreakablespace/makefile +++ b/nonbreakablespace/makefile @@ -1,6 +1,6 @@ DIFF ?= diff --strip-trailing-cr -u test: - @pandoc --lua-filter=nonbreakablespace.lua sample.md | $(DIFF) expected.html - - -.PHONY: test \ No newline at end of file + @pandoc --lua-filter=pandocVlna.lua sampleCZ.md | $(DIFF) expectedCZ.html - + @pandoc --lua-filter=pandocVlna.lua sampleEN.md | $(DIFF) expectedEN.html - +.PHONY: test From f78a1fa6382a4c8baf625fb4db308d316d0c9d28 Mon Sep 17 00:00:00 2001 From: Delanii <46751732+Delanii@users.noreply.github.com> Date: Sun, 8 Nov 2020 21:55:07 +0100 Subject: [PATCH 15/37] Delete expectedCZ.html --- nonbreakablespace/expectedCZ.html | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 nonbreakablespace/expectedCZ.html diff --git a/nonbreakablespace/expectedCZ.html b/nonbreakablespace/expectedCZ.html deleted file mode 100644 index 1b641ccf..00000000 --- a/nonbreakablespace/expectedCZ.html +++ /dev/null @@ -1,12 +0,0 @@ -

Tests

-

Basic test

-

a test i test k test o test s test u test v test z test A test I test K test O test S test U test V test Z test – test – test

-

Test with numbers

-

Test 19 test “19” test

-

Test of double prefixes.

-

A i test, i v test, a k test, a v test.

-

Test of block code

-
a = 5
-k = "test"
-

Test of inline code

-

Test a = 5 test

From 4b5d58a09f7f6e0365db7b754fda4adc942c8e3f Mon Sep 17 00:00:00 2001 From: Delanii <46751732+Delanii@users.noreply.github.com> Date: Sun, 8 Nov 2020 21:55:58 +0100 Subject: [PATCH 16/37] New test file with fixes error causes by SoftBreak element --- nonbreakablespace/expectedCZ.html | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 nonbreakablespace/expectedCZ.html diff --git a/nonbreakablespace/expectedCZ.html b/nonbreakablespace/expectedCZ.html new file mode 100644 index 00000000..ef5332d8 --- /dev/null +++ b/nonbreakablespace/expectedCZ.html @@ -0,0 +1,12 @@ +

Tests

+

Basic test

+

a test i test k test o test s test u test v test z test A test I test K test O test S test U test V test Z test – test – test

+

Test with numbers

+

Test 19 test “19” test

+

Test of double prefixes.

+

A i test, i v test, a k test, a v test.

+

Test of block code

+
a = 5
+k = "test"
+

Test of inline code

+

Test a = 5 test

From d5fce8bd40abd4879c76b68a7e3c882daeed7a67 Mon Sep 17 00:00:00 2001 From: Delanii <46751732+Delanii@users.noreply.github.com> Date: Sun, 8 Nov 2020 21:58:12 +0100 Subject: [PATCH 17/37] Now testing also for SoftBreak element Also added fixes per first review suggestion (at least partially) --- nonbreakablespace/pandocVlna.lua | 73 ++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 32 deletions(-) diff --git a/nonbreakablespace/pandocVlna.lua b/nonbreakablespace/pandocVlna.lua index fa84180a..27ce763f 100644 --- a/nonbreakablespace/pandocVlna.lua +++ b/nonbreakablespace/pandocVlna.lua @@ -16,7 +16,7 @@ local prefixesEN = { 'The' } -local prefixes = { +local prefixesCZ = { 'a', 'i', 'k', @@ -109,7 +109,8 @@ function find_dashes(my_dash) end --[[ -Function to determine Space element replacement for non-breakable space according to output format +Function to determine Space element replacement for non-breakable space +--according to output format --]] function insert_nonbreakable_space(format) @@ -142,54 +143,62 @@ function Inlines (inlines) local insert = insert_nonbreakable_space(FORMAT) for i = 1, #inlines do - if inlines[i].t == 'Space' then + + --assign elements to variables for simpler code writing + local currentEl = inlines[i] + local previousEl = inlines[i-1] + local nextEl = inlines[i+1] + + if currentEl.t == 'Space' + or currentEl.t == 'SoftBreak' then -- Check for one-letter prefixes in Str before Space - if inlines[i - 1].t == 'Str' then - local one_letter_prefix = find_one_letter_prefix(inlines[i - 1].text) - if one_letter_prefix == true then --- inlines[i] = pandoc.Str '\xc2\xa0' -- Both work + if previousEl.t == 'Str' then + local one_letter_prefix = find_one_letter_prefix(previousEl.text) + if one_letter_prefix == true then +-- inlines[i] = pandoc.Str '\xc2\xa0' -- Both work inlines[i] = insert end - end + end -- Check for dashes in Str after Space - if inlines[i + 1].t == 'Str' then - local dash = find_dashes(inlines[i + 1].text) - if dash == true then - inlines[i] = insert - end + if nextEl.t == 'Str' then + local dash = find_dashes(nextEl.text) + + if dash == true then + inlines[i] = insert end + end - -- Check for not fully parsed Str elements - Those might be products of - -- other filters, that were executed before this one + -- Check for not fully parsed Str elements - Those might be products of + -- other filters, that were executed before this one - if inlines[i + 1].t == 'Str' then - if string.match(inlines[i + 1].text, '%.*%s*[„]?%d+[“]?%s*%.*') then - inlines[i] = insert - end + if nextEl.t == 'Str' then + if string.match(nextEl.text, '%.*%s*[„]?%d+[“]?%s*%.*') then + inlines[i] = insert end + end end - --[[ - Check for Str containing sequence " prefix ", which might occur in case of - preceding filter creates it in one Str element. Also check, if quotation - mark is present introduced by "quotation.lua" filter - --]] - - if inlines[i].t == 'Str' then - for index, prefix in ipairs(prefixes) do - if string.match(inlines[i].text, '%.*%s+[„]?' .. prefix .. '[“]?%s+%.*') then - front, detection, replacement, back = string.match(inlines[i].c, - '(%.*)(%s+[„]?' .. prefix .. '[“]?)(%s+)(%.*)') - + --[[ + Check for Str containing sequence " prefix ", which might occur in case of + preceding filter creates it in one Str element. Also check, if quotation + mark is present introduced by "quotation.lua" filter + --]] + + if currentEl.t == 'Str' then + for index, prefix in ipairs(prefixes) do + if string.match(currentEl.text, '%.*%s+[„]?' .. prefix .. '[“]?%s+%.*') then + front, detection, replacement, back = string.match(currentEl.text, + '(%.*)(%s+[„]?' .. prefix .. '[“]?)(%s+)(%.*)') + inlines[i].text = front .. detection .. insert .. back - end end end + end end return inlines From 80a69006ccab2ef03e9b099f79aa20de03381647 Mon Sep 17 00:00:00 2001 From: Delanii <46751732+Delanii@users.noreply.github.com> Date: Sun, 8 Nov 2020 22:18:37 +0100 Subject: [PATCH 18/37] Delete expectedEN.html --- nonbreakablespace/expectedEN.html | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 nonbreakablespace/expectedEN.html diff --git a/nonbreakablespace/expectedEN.html b/nonbreakablespace/expectedEN.html deleted file mode 100644 index c1f2c504..00000000 --- a/nonbreakablespace/expectedEN.html +++ /dev/null @@ -1,12 +0,0 @@ -

Tests

-

Basic test

-

a test i test A test I test the test The test – test – test

-

Test with numbers

-

Test 19 test “19” test

-

Test of double prefixes.

-

A i test, i v test, a k test, a v test.

-

Test of block code

-
a = 5
-k = "test"
-

Test of inline code

-

Test a = 5 test

From 25a75644eb3764238134e19fea8ae63c386ca8b7 Mon Sep 17 00:00:00 2001 From: Delanii <46751732+Delanii@users.noreply.github.com> Date: Sun, 8 Nov 2020 22:19:11 +0100 Subject: [PATCH 19/37] New test file for english --- nonbreakablespace/expectedEN.html | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 nonbreakablespace/expectedEN.html diff --git a/nonbreakablespace/expectedEN.html b/nonbreakablespace/expectedEN.html new file mode 100644 index 00000000..c1f2c504 --- /dev/null +++ b/nonbreakablespace/expectedEN.html @@ -0,0 +1,12 @@ +

Tests

+

Basic test

+

a test i test A test I test the test The test – test – test

+

Test with numbers

+

Test 19 test “19” test

+

Test of double prefixes.

+

A i test, i v test, a k test, a v test.

+

Test of block code

+
a = 5
+k = "test"
+

Test of inline code

+

Test a = 5 test

From a4c6e8184688ec781bc65ee88fa72cf13de8d414 Mon Sep 17 00:00:00 2001 From: Delanii <46751732+Delanii@users.noreply.github.com> Date: Sun, 8 Nov 2020 22:43:03 +0100 Subject: [PATCH 20/37] Delete expectedEN.html --- nonbreakablespace/expectedEN.html | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 nonbreakablespace/expectedEN.html diff --git a/nonbreakablespace/expectedEN.html b/nonbreakablespace/expectedEN.html deleted file mode 100644 index c1f2c504..00000000 --- a/nonbreakablespace/expectedEN.html +++ /dev/null @@ -1,12 +0,0 @@ -

Tests

-

Basic test

-

a test i test A test I test the test The test – test – test

-

Test with numbers

-

Test 19 test “19” test

-

Test of double prefixes.

-

A i test, i v test, a k test, a v test.

-

Test of block code

-
a = 5
-k = "test"
-

Test of inline code

-

Test a = 5 test

From 5f13001c55c1d05c17b8b4ec86779349d244c905 Mon Sep 17 00:00:00 2001 From: Delanii <46751732+Delanii@users.noreply.github.com> Date: Sun, 8 Nov 2020 22:43:37 +0100 Subject: [PATCH 21/37] Another try for test file for english --- nonbreakablespace/expectedEN.html | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 nonbreakablespace/expectedEN.html diff --git a/nonbreakablespace/expectedEN.html b/nonbreakablespace/expectedEN.html new file mode 100644 index 00000000..c1f2c504 --- /dev/null +++ b/nonbreakablespace/expectedEN.html @@ -0,0 +1,12 @@ +

Tests

+

Basic test

+

a test i test A test I test the test The test – test – test

+

Test with numbers

+

Test 19 test “19” test

+

Test of double prefixes.

+

A i test, i v test, a k test, a v test.

+

Test of block code

+
a = 5
+k = "test"
+

Test of inline code

+

Test a = 5 test

From f060207288def2283e34e163c9d30f1826bf1485 Mon Sep 17 00:00:00 2001 From: Delanii <46751732+Delanii@users.noreply.github.com> Date: Tue, 10 Nov 2020 21:10:30 +0100 Subject: [PATCH 22/37] Delete README.md --- nonbreakablespace/README.md | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 nonbreakablespace/README.md diff --git a/nonbreakablespace/README.md b/nonbreakablespace/README.md deleted file mode 100644 index c9c81bf4..00000000 --- a/nonbreakablespace/README.md +++ /dev/null @@ -1,27 +0,0 @@ -# Non-breakable space filter - -This filter replaces regular spaces with non-breakable spaces according to -predefined conditions. Currently, this filter replaces regular spaces with -unbreakable ones after one-letter words (prefixes and conjunctions): -'a', 'i', 'k', 'o', 's', 'u', 'v', 'z'; and theyre uppercase variant. Also -inserts non-breakable spaces in front of en-dashes and in front of numbers. -Some extra effort is taken in detecting these patterns in *not-fully* parsed -strings (for example, if this filter is used after some macro replacing -filter). - -In this regard this filter functions similarly like TeX `vlna` preprocessor -or LuaTeX `luavlna` package. - -The default settings are conformant to Czech typography rules, but these can -be changed easily by user customization in filter file `nonbreakablespace.lua` -by changing contents of `prefixes` or `dashes` tables. - -Currently supported formats are: - -* LaTeX a ConTeXt -* Open Office Document -* MS Word -* HTML - -**NOTE**: Using this filter increases strain on line-breaking patterns. Whenever -possible, consider allowing hyphenation. From c02aa6944ac75aac7018239f0bf00757cadc284a Mon Sep 17 00:00:00 2001 From: Delanii <46751732+Delanii@users.noreply.github.com> Date: Tue, 10 Nov 2020 21:10:39 +0100 Subject: [PATCH 23/37] Delete expectedCZ.html --- nonbreakablespace/expectedCZ.html | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 nonbreakablespace/expectedCZ.html diff --git a/nonbreakablespace/expectedCZ.html b/nonbreakablespace/expectedCZ.html deleted file mode 100644 index ef5332d8..00000000 --- a/nonbreakablespace/expectedCZ.html +++ /dev/null @@ -1,12 +0,0 @@ -

Tests

-

Basic test

-

a test i test k test o test s test u test v test z test A test I test K test O test S test U test V test Z test – test – test

-

Test with numbers

-

Test 19 test “19” test

-

Test of double prefixes.

-

A i test, i v test, a k test, a v test.

-

Test of block code

-
a = 5
-k = "test"
-

Test of inline code

-

Test a = 5 test

From 22c7c82dda886dc81ce2a2ac13c2a223dbab15f1 Mon Sep 17 00:00:00 2001 From: Delanii <46751732+Delanii@users.noreply.github.com> Date: Tue, 10 Nov 2020 21:10:46 +0100 Subject: [PATCH 24/37] Delete expectedEN.html --- nonbreakablespace/expectedEN.html | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 nonbreakablespace/expectedEN.html diff --git a/nonbreakablespace/expectedEN.html b/nonbreakablespace/expectedEN.html deleted file mode 100644 index c1f2c504..00000000 --- a/nonbreakablespace/expectedEN.html +++ /dev/null @@ -1,12 +0,0 @@ -

Tests

-

Basic test

-

a test i test A test I test the test The test – test – test

-

Test with numbers

-

Test 19 test “19” test

-

Test of double prefixes.

-

A i test, i v test, a k test, a v test.

-

Test of block code

-
a = 5
-k = "test"
-

Test of inline code

-

Test a = 5 test

From fa6a2b8dd5508a83f9e957a6e33f5bb2ce0842ed Mon Sep 17 00:00:00 2001 From: Delanii <46751732+Delanii@users.noreply.github.com> Date: Tue, 10 Nov 2020 21:10:54 +0100 Subject: [PATCH 25/37] Delete makefile --- nonbreakablespace/makefile | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 nonbreakablespace/makefile diff --git a/nonbreakablespace/makefile b/nonbreakablespace/makefile deleted file mode 100644 index 3f634b1c..00000000 --- a/nonbreakablespace/makefile +++ /dev/null @@ -1,6 +0,0 @@ -DIFF ?= diff --strip-trailing-cr -u - -test: - @pandoc --lua-filter=pandocVlna.lua sampleCZ.md | $(DIFF) expectedCZ.html - - @pandoc --lua-filter=pandocVlna.lua sampleEN.md | $(DIFF) expectedEN.html - -.PHONY: test From 7008e813a138531a04ed8b9c8b0911b32e5b42bf Mon Sep 17 00:00:00 2001 From: Delanii <46751732+Delanii@users.noreply.github.com> Date: Tue, 10 Nov 2020 21:11:02 +0100 Subject: [PATCH 26/37] Delete pandocVlna.lua --- nonbreakablespace/pandocVlna.lua | 211 ------------------------------- 1 file changed, 211 deletions(-) delete mode 100644 nonbreakablespace/pandocVlna.lua diff --git a/nonbreakablespace/pandocVlna.lua b/nonbreakablespace/pandocVlna.lua deleted file mode 100644 index 27ce763f..00000000 --- a/nonbreakablespace/pandocVlna.lua +++ /dev/null @@ -1,211 +0,0 @@ -local utils = require 'pandoc.utils' -local stringify = utils.stringify - ---[[ -Indexed table of one-letter prefixes, after which should be inserted '\160'. -Verbose, but can be changed per user requirements. ---]] - -local prefixes = {} - -local prefixesEN = { - 'I', - 'a', - 'A', - 'the', - 'The' -} - -local prefixesCZ = { - 'a', - 'i', - 'k', - 'o', - 's', - 'u', - 'v', - 'z', - 'A', - 'I', - 'K', - 'O', - 'S', - 'U', - 'V', - 'Z' -} - --- Set `prefixes` according to `lang` metadata value -function Meta(meta) - if meta.lang then - langSet = stringify(meta.lang) - - if langSet == 'cs' then - prefixes = prefixesCZ - else - prefixes = prefixesEN --default to english prefixes - end - - else - prefixes = prefixesEN --default to english prefixes - end - - return prefixes -end - ---[[ -Some languages (czech among them) require nonbreakable space *before* long dash ---]] - -local dashes = { - '--', - '–' -} - ---[[ -Table of replacement elements ---]] - -local nonbreakablespaces = { - html = ' ', - latex = '~', - context = '~' -} - ---[[ -Function responsible for searching for one-letter prefixes, after which is -inserted non-breakable space. Function is short-circuited, that means: - -* If it finds match with `prefix` in `prefixes` table, then it returns `true`. -* Otherwise, after the iteration is finished, returns `false` (prefix wasnt -found). ---]] - -function find_one_letter_prefix(my_string) - for index, prefix in ipairs(prefixes) do - if my_string == prefix then - return true - end - end - return false -end - ---[[ -Function responsible for searching for dashes, before whose is inserted -non-breakable space. Function is short-circuited, that means: - -* If it finds match with `dash` in `dashes` table, then it returns `true`. -* Otherwise, after the iteration is finished, returns `false` (dash wasnt -found). ---]] - -function find_dashes(my_dash) - for index, dash in ipairs(dashes) do - if my_dash == dash then - return true - end - end - return false -end - ---[[ -Function to determine Space element replacement for non-breakable space ---according to output format ---]] - -function insert_nonbreakable_space(format) - if format == 'html' then - return pandoc.RawInline('html', nonbreakablespaces.html) - elseif format:match 'latex' then - return pandoc.RawInline('tex',nonbreakablespaces.latex) - elseif format:match 'context' then - return pandoc.RawInline('tex',nonbreakablespaces.latex) - else - --fallback to inserting non-breakable space unicode symbol - return pandoc.Str '\u{a0}' - end -end - ---[[ -Core filter function: - -* It iterates over all inline elements in block -* If it finds Space element, uses previously defined functions to find -`prefixes` or `dashes` -* Replaces Space element with `Str '\u{a0}'`, which is non-breakable space -representation -* Returns modified list of inlines ---]] - -function Inlines (inlines) - - --variable holding replacement value for the non-breakable space - local insert = insert_nonbreakable_space(FORMAT) - - for i = 1, #inlines do - - --assign elements to variables for simpler code writing - local currentEl = inlines[i] - local previousEl = inlines[i-1] - local nextEl = inlines[i+1] - - if currentEl.t == 'Space' - or currentEl.t == 'SoftBreak' then - - -- Check for one-letter prefixes in Str before Space - - if previousEl.t == 'Str' then - local one_letter_prefix = find_one_letter_prefix(previousEl.text) - if one_letter_prefix == true then --- inlines[i] = pandoc.Str '\xc2\xa0' -- Both work - inlines[i] = insert - end - end - - -- Check for dashes in Str after Space - - if nextEl.t == 'Str' then - local dash = find_dashes(nextEl.text) - - if dash == true then - inlines[i] = insert - end - end - - -- Check for not fully parsed Str elements - Those might be products of - -- other filters, that were executed before this one - - if nextEl.t == 'Str' then - if string.match(nextEl.text, '%.*%s*[„]?%d+[“]?%s*%.*') then - inlines[i] = insert - end - end - - end - - --[[ - Check for Str containing sequence " prefix ", which might occur in case of - preceding filter creates it in one Str element. Also check, if quotation - mark is present introduced by "quotation.lua" filter - --]] - - if currentEl.t == 'Str' then - for index, prefix in ipairs(prefixes) do - if string.match(currentEl.text, '%.*%s+[„]?' .. prefix .. '[“]?%s+%.*') then - front, detection, replacement, back = string.match(currentEl.text, - '(%.*)(%s+[„]?' .. prefix .. '[“]?)(%s+)(%.*)') - - inlines[i].text = front .. detection .. insert .. back - end - end - end - - end - return inlines -end - --- This should change the order of running functions: Meta - Inlines - rest ... -return { - {Meta = Meta}, - {Inlines = Inlines}, -} From a675d44fa2406128eb2ec1e8923c513fef5215e8 Mon Sep 17 00:00:00 2001 From: Delanii <46751732+Delanii@users.noreply.github.com> Date: Tue, 10 Nov 2020 21:11:11 +0100 Subject: [PATCH 27/37] Delete sampleCZ.md --- nonbreakablespace/sampleCZ.md | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 nonbreakablespace/sampleCZ.md diff --git a/nonbreakablespace/sampleCZ.md b/nonbreakablespace/sampleCZ.md deleted file mode 100644 index cb673095..00000000 --- a/nonbreakablespace/sampleCZ.md +++ /dev/null @@ -1,28 +0,0 @@ ---- -lang: cs ---- - -# Tests - -## Basic test - -a test i test k test o test s test u test v test z test A test I test K test O test S test U test V test Z test -- test – test - -## Test with numbers - -Test 19 test "19" test - -## Test of double prefixes. - -A i test, i v test, a k test, a v test. - -## Test of block code - -``` -a = 5 -k = "test" -``` - -## Test of inline code - -Test `a = 5` test From 5ebf029f6f98820f2e9ad86bfe678374be128ffb Mon Sep 17 00:00:00 2001 From: Delanii <46751732+Delanii@users.noreply.github.com> Date: Tue, 10 Nov 2020 21:11:22 +0100 Subject: [PATCH 28/37] Delete sampleEN.md --- nonbreakablespace/sampleEN.md | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 nonbreakablespace/sampleEN.md diff --git a/nonbreakablespace/sampleEN.md b/nonbreakablespace/sampleEN.md deleted file mode 100644 index 2184cd2f..00000000 --- a/nonbreakablespace/sampleEN.md +++ /dev/null @@ -1,28 +0,0 @@ ---- -lang: cs ---- - -# Tests - -## Basic test - -a test i test A test I test the test The test -- test – test - -## Test with numbers - -Test 19 test "19" test - -## Test of double prefixes. - -A i test, i v test, a k test, a v test. - -## Test of block code - -``` -a = 5 -k = "test" -``` - -## Test of inline code - -Test `a = 5` test From bc67eb1bd1df5fb8f8eda9a3a5c632cf8c1c2cf5 Mon Sep 17 00:00:00 2001 From: Delanii <46751732+Delanii@users.noreply.github.com> Date: Tue, 10 Nov 2020 21:16:08 +0100 Subject: [PATCH 29/37] Reupload Complete reupload of new files because fo failing tests. --- nonbreakablespace/README.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 nonbreakablespace/README.md diff --git a/nonbreakablespace/README.md b/nonbreakablespace/README.md new file mode 100644 index 00000000..796f9a8d --- /dev/null +++ b/nonbreakablespace/README.md @@ -0,0 +1,27 @@ +# Non-breakable space filter + +This filter replaces regular spaces with non-breakable spaces according to +predefined conditions. Currently, this filter replaces regular spaces with +unbreakable ones after one-letter words (prefixes and conjunctions): +'a', 'i', 'k', 'o', 's', 'u', 'v', 'z'; and theyre uppercase variant. Also +inserts non-breakable spaces in front of en-dashes and in front of numbers. +Some extra effort is taken in detecting these patterns in *not-fully* parsed +strings (for example, if this filter is used after some macro replacing +filter). + +In this regard this filter functions similarly like TeX `vlna` preprocessor +or LuaTeX `luavlna` package. + +The default settings are conformant to Czech typography rules, but these can +be changed easily by user customization in filter file `nonbreakablespace.lua` +by changing contents of `prefixes` or `dashes` tables. + +Currently supported formats are: + +* LaTeX a ConTeXt +* Open Office Document +* MS Word +* HTML + +**NOTE**: Using this filter increases strain on line-breaking patterns. Whenever +possible, consider allowing hyphenation. From 7de7a14e1b5204034c6fee014d9c13ac6726c929 Mon Sep 17 00:00:00 2001 From: Delanii <46751732+Delanii@users.noreply.github.com> Date: Tue, 10 Nov 2020 21:17:06 +0100 Subject: [PATCH 30/37] Add files via upload Complete reupload --- nonbreakablespace/expectedCZ.html | 12 ++ nonbreakablespace/expectedEN.html | 12 ++ nonbreakablespace/makefile | 6 + nonbreakablespace/pandocVlna.lua | 211 ++++++++++++++++++++++++++++++ nonbreakablespace/sampleCZ.md | 29 ++++ nonbreakablespace/sampleEN.md | 24 ++++ 6 files changed, 294 insertions(+) create mode 100644 nonbreakablespace/expectedCZ.html create mode 100644 nonbreakablespace/expectedEN.html create mode 100644 nonbreakablespace/makefile create mode 100644 nonbreakablespace/pandocVlna.lua create mode 100644 nonbreakablespace/sampleCZ.md create mode 100644 nonbreakablespace/sampleEN.md diff --git a/nonbreakablespace/expectedCZ.html b/nonbreakablespace/expectedCZ.html new file mode 100644 index 00000000..ef5332d8 --- /dev/null +++ b/nonbreakablespace/expectedCZ.html @@ -0,0 +1,12 @@ +

Tests

+

Basic test

+

a test i test k test o test s test u test v test z test A test I test K test O test S test U test V test Z test – test – test

+

Test with numbers

+

Test 19 test “19” test

+

Test of double prefixes.

+

A i test, i v test, a k test, a v test.

+

Test of block code

+
a = 5
+k = "test"
+

Test of inline code

+

Test a = 5 test

diff --git a/nonbreakablespace/expectedEN.html b/nonbreakablespace/expectedEN.html new file mode 100644 index 00000000..c1f2c504 --- /dev/null +++ b/nonbreakablespace/expectedEN.html @@ -0,0 +1,12 @@ +

Tests

+

Basic test

+

a test i test A test I test the test The test – test – test

+

Test with numbers

+

Test 19 test “19” test

+

Test of double prefixes.

+

A i test, i v test, a k test, a v test.

+

Test of block code

+
a = 5
+k = "test"
+

Test of inline code

+

Test a = 5 test

diff --git a/nonbreakablespace/makefile b/nonbreakablespace/makefile new file mode 100644 index 00000000..3f634b1c --- /dev/null +++ b/nonbreakablespace/makefile @@ -0,0 +1,6 @@ +DIFF ?= diff --strip-trailing-cr -u + +test: + @pandoc --lua-filter=pandocVlna.lua sampleCZ.md | $(DIFF) expectedCZ.html - + @pandoc --lua-filter=pandocVlna.lua sampleEN.md | $(DIFF) expectedEN.html - +.PHONY: test diff --git a/nonbreakablespace/pandocVlna.lua b/nonbreakablespace/pandocVlna.lua new file mode 100644 index 00000000..27ce763f --- /dev/null +++ b/nonbreakablespace/pandocVlna.lua @@ -0,0 +1,211 @@ +local utils = require 'pandoc.utils' +local stringify = utils.stringify + +--[[ +Indexed table of one-letter prefixes, after which should be inserted '\160'. +Verbose, but can be changed per user requirements. +--]] + +local prefixes = {} + +local prefixesEN = { + 'I', + 'a', + 'A', + 'the', + 'The' +} + +local prefixesCZ = { + 'a', + 'i', + 'k', + 'o', + 's', + 'u', + 'v', + 'z', + 'A', + 'I', + 'K', + 'O', + 'S', + 'U', + 'V', + 'Z' +} + +-- Set `prefixes` according to `lang` metadata value +function Meta(meta) + if meta.lang then + langSet = stringify(meta.lang) + + if langSet == 'cs' then + prefixes = prefixesCZ + else + prefixes = prefixesEN --default to english prefixes + end + + else + prefixes = prefixesEN --default to english prefixes + end + + return prefixes +end + +--[[ +Some languages (czech among them) require nonbreakable space *before* long dash +--]] + +local dashes = { + '--', + '–' +} + +--[[ +Table of replacement elements +--]] + +local nonbreakablespaces = { + html = ' ', + latex = '~', + context = '~' +} + +--[[ +Function responsible for searching for one-letter prefixes, after which is +inserted non-breakable space. Function is short-circuited, that means: + +* If it finds match with `prefix` in `prefixes` table, then it returns `true`. +* Otherwise, after the iteration is finished, returns `false` (prefix wasnt +found). +--]] + +function find_one_letter_prefix(my_string) + for index, prefix in ipairs(prefixes) do + if my_string == prefix then + return true + end + end + return false +end + +--[[ +Function responsible for searching for dashes, before whose is inserted +non-breakable space. Function is short-circuited, that means: + +* If it finds match with `dash` in `dashes` table, then it returns `true`. +* Otherwise, after the iteration is finished, returns `false` (dash wasnt +found). +--]] + +function find_dashes(my_dash) + for index, dash in ipairs(dashes) do + if my_dash == dash then + return true + end + end + return false +end + +--[[ +Function to determine Space element replacement for non-breakable space +--according to output format +--]] + +function insert_nonbreakable_space(format) + if format == 'html' then + return pandoc.RawInline('html', nonbreakablespaces.html) + elseif format:match 'latex' then + return pandoc.RawInline('tex',nonbreakablespaces.latex) + elseif format:match 'context' then + return pandoc.RawInline('tex',nonbreakablespaces.latex) + else + --fallback to inserting non-breakable space unicode symbol + return pandoc.Str '\u{a0}' + end +end + +--[[ +Core filter function: + +* It iterates over all inline elements in block +* If it finds Space element, uses previously defined functions to find +`prefixes` or `dashes` +* Replaces Space element with `Str '\u{a0}'`, which is non-breakable space +representation +* Returns modified list of inlines +--]] + +function Inlines (inlines) + + --variable holding replacement value for the non-breakable space + local insert = insert_nonbreakable_space(FORMAT) + + for i = 1, #inlines do + + --assign elements to variables for simpler code writing + local currentEl = inlines[i] + local previousEl = inlines[i-1] + local nextEl = inlines[i+1] + + if currentEl.t == 'Space' + or currentEl.t == 'SoftBreak' then + + -- Check for one-letter prefixes in Str before Space + + if previousEl.t == 'Str' then + local one_letter_prefix = find_one_letter_prefix(previousEl.text) + if one_letter_prefix == true then +-- inlines[i] = pandoc.Str '\xc2\xa0' -- Both work + inlines[i] = insert + end + end + + -- Check for dashes in Str after Space + + if nextEl.t == 'Str' then + local dash = find_dashes(nextEl.text) + + if dash == true then + inlines[i] = insert + end + end + + -- Check for not fully parsed Str elements - Those might be products of + -- other filters, that were executed before this one + + if nextEl.t == 'Str' then + if string.match(nextEl.text, '%.*%s*[„]?%d+[“]?%s*%.*') then + inlines[i] = insert + end + end + + end + + --[[ + Check for Str containing sequence " prefix ", which might occur in case of + preceding filter creates it in one Str element. Also check, if quotation + mark is present introduced by "quotation.lua" filter + --]] + + if currentEl.t == 'Str' then + for index, prefix in ipairs(prefixes) do + if string.match(currentEl.text, '%.*%s+[„]?' .. prefix .. '[“]?%s+%.*') then + front, detection, replacement, back = string.match(currentEl.text, + '(%.*)(%s+[„]?' .. prefix .. '[“]?)(%s+)(%.*)') + + inlines[i].text = front .. detection .. insert .. back + end + end + end + + end + return inlines +end + +-- This should change the order of running functions: Meta - Inlines - rest ... +return { + {Meta = Meta}, + {Inlines = Inlines}, +} diff --git a/nonbreakablespace/sampleCZ.md b/nonbreakablespace/sampleCZ.md new file mode 100644 index 00000000..0aaf8988 --- /dev/null +++ b/nonbreakablespace/sampleCZ.md @@ -0,0 +1,29 @@ +--- +lang: cs +--- + +# Tests + +## Basic test + +a test i test k test o test s test u test v test z test A test I test K test O +test S test U test V test Z test -- test – test + +## Test with numbers + +Test 19 test "19" test + +## Test of double prefixes. + +A i test, i v test, a k test, a v test. + +## Test of block code + +``` +a = 5 +k = "test" +``` + +## Test of inline code + +Test `a = 5` test diff --git a/nonbreakablespace/sampleEN.md b/nonbreakablespace/sampleEN.md new file mode 100644 index 00000000..5dc87fa1 --- /dev/null +++ b/nonbreakablespace/sampleEN.md @@ -0,0 +1,24 @@ +# Tests + +## Basic test + +a test i test A test I test the test The test -- test – test + +## Test with numbers + +Test 19 test "19" test + +## Test of double prefixes. + +A i test, i v test, a k test, a v test. + +## Test of block code + +``` +a = 5 +k = "test" +``` + +## Test of inline code + +Test `a = 5` test From 76b00e79bbef94749026424c01d325ca59579782 Mon Sep 17 00:00:00 2001 From: Delanii <46751732+Delanii@users.noreply.github.com> Date: Wed, 11 Nov 2020 20:40:59 +0100 Subject: [PATCH 31/37] Update pandocVlna.lua Fixed review suggestion no. 2 --- nonbreakablespace/pandocVlna.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nonbreakablespace/pandocVlna.lua b/nonbreakablespace/pandocVlna.lua index 27ce763f..3980923d 100644 --- a/nonbreakablespace/pandocVlna.lua +++ b/nonbreakablespace/pandocVlna.lua @@ -142,7 +142,7 @@ function Inlines (inlines) --variable holding replacement value for the non-breakable space local insert = insert_nonbreakable_space(FORMAT) - for i = 1, #inlines do + for i = 2, #inlines do --assign elements to variables for simpler code writing local currentEl = inlines[i] From 11794ffa3fc6b5292aad213c303feea067be7105 Mon Sep 17 00:00:00 2001 From: Delanii <46751732+Delanii@users.noreply.github.com> Date: Wed, 11 Nov 2020 20:59:29 +0100 Subject: [PATCH 32/37] Delete pandocVlna.lua about to reupload new one --- nonbreakablespace/pandocVlna.lua | 211 ------------------------------- 1 file changed, 211 deletions(-) delete mode 100644 nonbreakablespace/pandocVlna.lua diff --git a/nonbreakablespace/pandocVlna.lua b/nonbreakablespace/pandocVlna.lua deleted file mode 100644 index 3980923d..00000000 --- a/nonbreakablespace/pandocVlna.lua +++ /dev/null @@ -1,211 +0,0 @@ -local utils = require 'pandoc.utils' -local stringify = utils.stringify - ---[[ -Indexed table of one-letter prefixes, after which should be inserted '\160'. -Verbose, but can be changed per user requirements. ---]] - -local prefixes = {} - -local prefixesEN = { - 'I', - 'a', - 'A', - 'the', - 'The' -} - -local prefixesCZ = { - 'a', - 'i', - 'k', - 'o', - 's', - 'u', - 'v', - 'z', - 'A', - 'I', - 'K', - 'O', - 'S', - 'U', - 'V', - 'Z' -} - --- Set `prefixes` according to `lang` metadata value -function Meta(meta) - if meta.lang then - langSet = stringify(meta.lang) - - if langSet == 'cs' then - prefixes = prefixesCZ - else - prefixes = prefixesEN --default to english prefixes - end - - else - prefixes = prefixesEN --default to english prefixes - end - - return prefixes -end - ---[[ -Some languages (czech among them) require nonbreakable space *before* long dash ---]] - -local dashes = { - '--', - '–' -} - ---[[ -Table of replacement elements ---]] - -local nonbreakablespaces = { - html = ' ', - latex = '~', - context = '~' -} - ---[[ -Function responsible for searching for one-letter prefixes, after which is -inserted non-breakable space. Function is short-circuited, that means: - -* If it finds match with `prefix` in `prefixes` table, then it returns `true`. -* Otherwise, after the iteration is finished, returns `false` (prefix wasnt -found). ---]] - -function find_one_letter_prefix(my_string) - for index, prefix in ipairs(prefixes) do - if my_string == prefix then - return true - end - end - return false -end - ---[[ -Function responsible for searching for dashes, before whose is inserted -non-breakable space. Function is short-circuited, that means: - -* If it finds match with `dash` in `dashes` table, then it returns `true`. -* Otherwise, after the iteration is finished, returns `false` (dash wasnt -found). ---]] - -function find_dashes(my_dash) - for index, dash in ipairs(dashes) do - if my_dash == dash then - return true - end - end - return false -end - ---[[ -Function to determine Space element replacement for non-breakable space ---according to output format ---]] - -function insert_nonbreakable_space(format) - if format == 'html' then - return pandoc.RawInline('html', nonbreakablespaces.html) - elseif format:match 'latex' then - return pandoc.RawInline('tex',nonbreakablespaces.latex) - elseif format:match 'context' then - return pandoc.RawInline('tex',nonbreakablespaces.latex) - else - --fallback to inserting non-breakable space unicode symbol - return pandoc.Str '\u{a0}' - end -end - ---[[ -Core filter function: - -* It iterates over all inline elements in block -* If it finds Space element, uses previously defined functions to find -`prefixes` or `dashes` -* Replaces Space element with `Str '\u{a0}'`, which is non-breakable space -representation -* Returns modified list of inlines ---]] - -function Inlines (inlines) - - --variable holding replacement value for the non-breakable space - local insert = insert_nonbreakable_space(FORMAT) - - for i = 2, #inlines do - - --assign elements to variables for simpler code writing - local currentEl = inlines[i] - local previousEl = inlines[i-1] - local nextEl = inlines[i+1] - - if currentEl.t == 'Space' - or currentEl.t == 'SoftBreak' then - - -- Check for one-letter prefixes in Str before Space - - if previousEl.t == 'Str' then - local one_letter_prefix = find_one_letter_prefix(previousEl.text) - if one_letter_prefix == true then --- inlines[i] = pandoc.Str '\xc2\xa0' -- Both work - inlines[i] = insert - end - end - - -- Check for dashes in Str after Space - - if nextEl.t == 'Str' then - local dash = find_dashes(nextEl.text) - - if dash == true then - inlines[i] = insert - end - end - - -- Check for not fully parsed Str elements - Those might be products of - -- other filters, that were executed before this one - - if nextEl.t == 'Str' then - if string.match(nextEl.text, '%.*%s*[„]?%d+[“]?%s*%.*') then - inlines[i] = insert - end - end - - end - - --[[ - Check for Str containing sequence " prefix ", which might occur in case of - preceding filter creates it in one Str element. Also check, if quotation - mark is present introduced by "quotation.lua" filter - --]] - - if currentEl.t == 'Str' then - for index, prefix in ipairs(prefixes) do - if string.match(currentEl.text, '%.*%s+[„]?' .. prefix .. '[“]?%s+%.*') then - front, detection, replacement, back = string.match(currentEl.text, - '(%.*)(%s+[„]?' .. prefix .. '[“]?)(%s+)(%.*)') - - inlines[i].text = front .. detection .. insert .. back - end - end - end - - end - return inlines -end - --- This should change the order of running functions: Meta - Inlines - rest ... -return { - {Meta = Meta}, - {Inlines = Inlines}, -} From 7536ba9902394d25d8748da4399c91f194b961ad Mon Sep 17 00:00:00 2001 From: Delanii <46751732+Delanii@users.noreply.github.com> Date: Wed, 11 Nov 2020 21:00:08 +0100 Subject: [PATCH 33/37] Add files via upload Changes per review suggestion 3 and 4. --- nonbreakablespace/pandocVlna.lua | 172 +++++++++++++++++++++++++++++++ 1 file changed, 172 insertions(+) create mode 100644 nonbreakablespace/pandocVlna.lua diff --git a/nonbreakablespace/pandocVlna.lua b/nonbreakablespace/pandocVlna.lua new file mode 100644 index 00000000..6232afc6 --- /dev/null +++ b/nonbreakablespace/pandocVlna.lua @@ -0,0 +1,172 @@ +local utils = require 'pandoc.utils' +local stringify = utils.stringify + +--[[ +Indexed table of one-letter prefixes, after which should be inserted '\160'. +Verbose, but can be changed per user requirements. +--]] + +local prefixes = {} + +local prefixesEN = { + ['I'] = true, + ['a'] = true, + ['A'] = true, + ['the'] = true, + ['The'] = true +} + +local prefixesCZ = { + ['a'] = true, + ['i'] = true, + ['k'] = true, + ['o'] = true, + ['s'] = true, + ['u'] = true, + ['v'] = true, + ['z'] = true, + ['A'] = true, + ['I'] = true, + ['K'] = true, + ['O'] = true, + ['S'] = true, + ['U'] = true, + ['V'] = true, + ['Z'] = true +} + +-- Set `prefixes` according to `lang` metadata value +function Meta(meta) + if meta.lang then + langSet = stringify(meta.lang) + + if langSet == 'cs' then + prefixes = prefixesCZ + else + prefixes = prefixesEN --default to english prefixes + end + + else + prefixes = prefixesEN --default to english prefixes + end + + return prefixes +end + +--[[ +Some languages (czech among them) require nonbreakable space *before* long dash +--]] + +local dashes = { + ['--'] = true, + ['–'] = true +} + +--[[ +Table of replacement elements +--]] + +local nonbreakablespaces = { + html = ' ', + latex = '~', + context = '~' +} + +--[[ +Function to determine Space element replacement for non-breakable space +--according to output format +--]] + +function insert_nonbreakable_space(format) + if format == 'html' then + return pandoc.RawInline('html', nonbreakablespaces.html) + elseif format:match 'latex' then + return pandoc.RawInline('tex',nonbreakablespaces.latex) + elseif format:match 'context' then + return pandoc.RawInline('tex',nonbreakablespaces.latex) + else + --fallback to inserting non-breakable space unicode symbol + return pandoc.Str '\u{a0}' + end +end + +--[[ +Core filter function: + +* It iterates over all inline elements in block +* If it finds Space element, uses previously defined functions to find +`prefixes` or `dashes` +* Replaces Space element with `Str '\u{a0}'`, which is non-breakable space +representation +* Returns modified list of inlines +--]] + +function Inlines (inlines) + + --variable holding replacement value for the non-breakable space + local insert = insert_nonbreakable_space(FORMAT) + + for i = 2, #inlines do + + --assign elements to variables for simpler code writing + local currentEl = inlines[i] + local previousEl = inlines[i-1] + local nextEl = inlines[i+1] + + if currentEl.t == 'Space' + or currentEl.t == 'SoftBreak' then + + -- Check for one-letter prefixes in Str before Space + + if previousEl.t == 'Str' then + if prefixes[previousEl.text]== true then +-- inlines[i] = pandoc.Str '\xc2\xa0' -- Both work + inlines[i] = insert + end + end + + -- Check for dashes in Str after Space + + if nextEl.t == 'Str' then + if dashes[nextEl.text] == true then + inlines[i] = insert + end + end + + -- Check for not fully parsed Str elements - Those might be products of + -- other filters, that were executed before this one + + if nextEl.t == 'Str' then + if string.match(nextEl.text, '%.*%s*[„]?%d+[“]?%s*%.*') then + inlines[i] = insert + end + end + + end + + --[[ + Check for Str containing sequence " prefix ", which might occur in case of + preceding filter creates it in one Str element. Also check, if quotation + mark is present introduced by "quotation.lua" filter + --]] + + if currentEl.t == 'Str' then + for index, prefix in ipairs(prefixes) do + if string.match(currentEl.text, '%.*%s+[„]?' .. prefix .. '[“]?%s+%.*') then + front, detection, replacement, back = string.match(currentEl.text, + '(%.*)(%s+[„]?' .. prefix .. '[“]?)(%s+)(%.*)') + + inlines[i].text = front .. detection .. insert .. back + end + end + end + + end + return inlines +end + +-- This should change the order of running functions: Meta - Inlines - rest ... +return { + {Meta = Meta}, + {Inlines = Inlines}, +} From dad0797295d1187a5568bf39f4724865a0dae3eb Mon Sep 17 00:00:00 2001 From: Delanii <46751732+Delanii@users.noreply.github.com> Date: Sun, 22 Nov 2020 13:30:38 +0100 Subject: [PATCH 34/37] Rewrite or README.md: Default setting to English --- nonbreakablespace/README.md | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/nonbreakablespace/README.md b/nonbreakablespace/README.md index 796f9a8d..7f534958 100644 --- a/nonbreakablespace/README.md +++ b/nonbreakablespace/README.md @@ -1,20 +1,24 @@ # Non-breakable space filter This filter replaces regular spaces with non-breakable spaces according to -predefined conditions. Currently, this filter replaces regular spaces with -unbreakable ones after one-letter words (prefixes and conjunctions): -'a', 'i', 'k', 'o', 's', 'u', 'v', 'z'; and theyre uppercase variant. Also -inserts non-breakable spaces in front of en-dashes and in front of numbers. +predefined conditions. + +Rules for space replacement are defined for two languages: English and Czech +(default is English) in `prefixes` tables. Also, non-breakable spaces are +inserted in front of dashes and in front of numbers. Rules for inserting +non-breakable spaces in English are not as firm as in authors native language +(Czech), but some typographic conventions suggest to insert non-breakable space +after words: "I", "the", "The", "a", "A". Any suggestions regarding improvement +of English support in this filter are highly welcome. Some extra effort is taken in detecting these patterns in *not-fully* parsed strings (for example, if this filter is used after some macro replacing filter). In this regard this filter functions similarly like TeX `vlna` preprocessor -or LuaTeX `luavlna` package. +(only Czech) or LuaTeX `luavlna` package (international). -The default settings are conformant to Czech typography rules, but these can -be changed easily by user customization in filter file `nonbreakablespace.lua` -by changing contents of `prefixes` or `dashes` tables. +The default settings can be changed easily by user customization in filter file +`pandocVlna.lua` by changing contents of `prefixes` or `dashes` tables. Currently supported formats are: @@ -23,5 +27,7 @@ Currently supported formats are: * MS Word * HTML +For other formats filter defaults to insert escaped Unicode sequence `\u{a0}`. + **NOTE**: Using this filter increases strain on line-breaking patterns. Whenever possible, consider allowing hyphenation. From 8f7501f0ac0c277d7932d7a7c1be71406a05f801 Mon Sep 17 00:00:00 2001 From: Delanii <46751732+Delanii@users.noreply.github.com> Date: Sun, 22 Nov 2020 13:33:35 +0100 Subject: [PATCH 35/37] Update per suggestions in PR Also updated file header according to new contribution guide. --- nonbreakablespace/pandocVlna.lua | 70 +++++++++++++++++++------------- 1 file changed, 41 insertions(+), 29 deletions(-) diff --git a/nonbreakablespace/pandocVlna.lua b/nonbreakablespace/pandocVlna.lua index 6232afc6..d508704e 100644 --- a/nonbreakablespace/pandocVlna.lua +++ b/nonbreakablespace/pandocVlna.lua @@ -1,8 +1,21 @@ +--[[ +pandocVlna.lua - Filter to automatically insert non-breakable spaces in specific +locations in text. + +Currently supports czech and english languages, with default being set to +english. PRs or suggestions leading to improvement of current features or +to add supported for other languages is highly welcome. +Inspired by simillar tools in TeX toolchain: `luavlna` and `vlna`. + +Author: Tomas Krulis (with substantial help from Albert Krewinkel) +License: MIT - more details in LICENSE file in repository root directory +--]] + local utils = require 'pandoc.utils' local stringify = utils.stringify --[[ -Indexed table of one-letter prefixes, after which should be inserted '\160'. +Table of one-letter prefixes, after which should be inserted '\160'. Verbose, but can be changed per user requirements. --]] @@ -74,7 +87,7 @@ local nonbreakablespaces = { --[[ Function to determine Space element replacement for non-breakable space ---according to output format +according to output format --]] function insert_nonbreakable_space(format) @@ -85,7 +98,8 @@ function insert_nonbreakable_space(format) elseif format:match 'context' then return pandoc.RawInline('tex',nonbreakablespaces.latex) else - --fallback to inserting non-breakable space unicode symbol + -- fallback to inserting non-breakable space unicode symbol + -- pandoc.Str '\xc2\xa0' -- also works return pandoc.Str '\u{a0}' end end @@ -103,12 +117,13 @@ representation function Inlines (inlines) - --variable holding replacement value for the non-breakable space - local insert = insert_nonbreakable_space(FORMAT) + -- variable holding replacement value for the non-breakable space + local nbsp = insert_nonbreakable_space(FORMAT) - for i = 2, #inlines do + for i = 2, #inlines do -- test from second position, to prevent error if + -- `Space` element would be first in `Inlines` block - --assign elements to variables for simpler code writing + --assign elements to variables for more readability local currentEl = inlines[i] local previousEl = inlines[i-1] local nextEl = inlines[i+1] @@ -118,45 +133,42 @@ function Inlines (inlines) -- Check for one-letter prefixes in Str before Space - if previousEl.t == 'Str' then - if prefixes[previousEl.text]== true then --- inlines[i] = pandoc.Str '\xc2\xa0' -- Both work - inlines[i] = insert - end + if previousEl.t == 'Str' and prefixes[previousEl.text] then + -- if elements in table (`prefixes`) are mapped to bolean values, + -- it is possible to test like `prefixes[argument]` instead of + -- `if prefixes[argument] == true` + inlines[i] = nbsp end -- Check for dashes in Str after Space - if nextEl.t == 'Str' then - if dashes[nextEl.text] == true then - inlines[i] = insert - end + if nextEl.t == 'Str' and dashes[nextEl.text] then + inlines[i] = nbsp end - -- Check for not fully parsed Str elements - Those might be products of - -- other filters, that were executed before this one + -- Check for digit `Str` elements. Those elements might not be fully + -- parsed (in case there were other filters executed before this one), + -- so following regex checks for any characters or whitespace wrapping + -- around `Str` element containing digits - if nextEl.t == 'Str' then - if string.match(nextEl.text, '%.*%s*[„]?%d+[“]?%s*%.*') then - inlines[i] = insert - end + if nextEl.t == 'Str' and string.match(nextEl.text, '%.*%s*%d+%s*%.*') then + inlines[i] = nbsp end end --[[ Check for Str containing sequence " prefix ", which might occur in case of - preceding filter creates it in one Str element. Also check, if quotation - mark is present introduced by "quotation.lua" filter + preceding filter creates it inside Str element. --]] if currentEl.t == 'Str' then - for index, prefix in ipairs(prefixes) do - if string.match(currentEl.text, '%.*%s+[„]?' .. prefix .. '[“]?%s+%.*') then - front, detection, replacement, back = string.match(currentEl.text, - '(%.*)(%s+[„]?' .. prefix .. '[“]?)(%s+)(%.*)') + for prefix, _ in pairs(prefixes) do + if string.match(currentEl.text, '%.*%s+' .. prefix .. '%s+%.*') then + front, detection, replacement, back = string.match(currentEl.text, + '(%.*)(%s+' .. prefix .. ')(%s+)(%.*)') - inlines[i].text = front .. detection .. insert .. back + inlines[i].text = front .. detection .. nbsp .. back end end end From ce063f3c624e81b98f7823c0edc635376a83abe1 Mon Sep 17 00:00:00 2001 From: Delanii <46751732+Delanii@users.noreply.github.com> Date: Wed, 2 Dec 2020 17:29:34 +0100 Subject: [PATCH 36/37] Bugfix I was returning from Meta function, which caused destruction of all metadata. That should be fixed now, Hopefully it will fix the filter tests too. --- nonbreakablespace/pandocVlna.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/nonbreakablespace/pandocVlna.lua b/nonbreakablespace/pandocVlna.lua index d508704e..47545d6f 100644 --- a/nonbreakablespace/pandocVlna.lua +++ b/nonbreakablespace/pandocVlna.lua @@ -63,7 +63,6 @@ function Meta(meta) prefixes = prefixesEN --default to english prefixes end - return prefixes end --[[ From d407e902fdd6be0b1701e8fa6858eea417dfe3d5 Mon Sep 17 00:00:00 2001 From: Delanii <46751732+Delanii@users.noreply.github.com> Date: Tue, 2 Mar 2021 12:16:15 +0100 Subject: [PATCH 37/37] Bugfix if last element in par block is "Space" The filter failed if last element in paragraph would be "Space" (result of other filter or from writing), similarly to case when "Space" would be first element of par block. Fixed now in replacement loop beginning (line 122) --- nonbreakablespace/pandocVlna.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nonbreakablespace/pandocVlna.lua b/nonbreakablespace/pandocVlna.lua index 47545d6f..0bbce484 100644 --- a/nonbreakablespace/pandocVlna.lua +++ b/nonbreakablespace/pandocVlna.lua @@ -119,7 +119,7 @@ function Inlines (inlines) -- variable holding replacement value for the non-breakable space local nbsp = insert_nonbreakable_space(FORMAT) - for i = 2, #inlines do -- test from second position, to prevent error if + for i = 2, #inlines-1 do -- test from second position, to prevent error if -- `Space` element would be first in `Inlines` block --assign elements to variables for more readability