Skip to content
This repository has been archived by the owner on May 19, 2023. It is now read-only.

Commit

Permalink
Merge pull request #66 from aireilly/seq-tweak
Browse files Browse the repository at this point in the history
Tweaks the callout rules
  • Loading branch information
rohennes committed May 4, 2023
2 parents 1639547 + d8c40a5 commit 66570e8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,3 @@ get '/hi' do <7> <8>
<6> Again, some text
<7> Moar text
<8> Again, some more text

//vale-fixture
[source,ruby]
----
require 'sinatra' <1>
get '/hi' do <3>
get '/hi' do <4>
----
<1> Test
<2> Test
2 changes: 1 addition & 1 deletion .vale/styles/AsciiDoc/MatchingNumberedCallouts.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
extends: script
message: "Missing numbered callout."
message: "Corresponding callout not found."
level: error
link: https://docs.asciidoctor.org/asciidoc/latest/verbatim/callouts/
scope: raw
Expand Down
6 changes: 3 additions & 3 deletions .vale/styles/AsciiDoc/SequentialNumberedCallouts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ script: |
scope += "\n"
prev_num := 0
numbered_callout_regex := ".*<(\\d+)>"
callout_regex := "^<(\\d+)>"
listingblock_delim_regex := "^-{4,}$"
for line in text.split(scope, "\n") {
Expand All @@ -23,7 +23,7 @@ script: |
prev_num = 0
}
if text.re_match(numbered_callout_regex, line) {
if text.re_match(callout_regex, line) {
callout := text.re_find("<(\\d+)>", line)
for key, value in callout {
//trim angle brackets from string
Expand All @@ -33,7 +33,7 @@ script: |
//cast string > int
num := text.atoi(trimmed)
//start counting
if num != prev_num && num != prev_num+1 {
if num != prev_num+1 {
start := text.index(scope, line)
matches = append(matches, {begin: start, end: start + len(line)})
}
Expand Down
8 changes: 4 additions & 4 deletions scripts/SequentialNumberedCallouts.tengo
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Tengo Language
Checks that callouts are sequential
Checks that callouts outside the listing block are sequential
$ tengo SequentialNumberedCallouts.tengo <asciidoc_file_to_validate>
*/

Expand All @@ -18,7 +18,7 @@ scope = text.trim_space(scope)
scope += "\n"

prev_num := 0
numbered_callout_regex := ".*<(\\d+)>"
callout_regex := "^<(\\d+)>"
listingblock_delim_regex := "^-{4,}$"

for line in text.split(scope, "\n") {
Expand All @@ -27,7 +27,7 @@ for line in text.split(scope, "\n") {
prev_num = 0
}

if text.re_match(numbered_callout_regex, line) {
if text.re_match(callout_regex, line) {
callout := text.re_find("<(\\d+)>", line)
for key, value in callout {
//trim angle brackets from string
Expand All @@ -37,7 +37,7 @@ for line in text.split(scope, "\n") {
//cast string > int
num := text.atoi(trimmed)
//start counting
if num != prev_num && num != prev_num+1 {
if num != prev_num+1 {
start := text.index(scope, line)
matches = append(matches, {begin: start, end: start + len(line)})
}
Expand Down

0 comments on commit 66570e8

Please sign in to comment.