From df3d77e2e5a397b636f7d698cbf1f9dbe67b219f Mon Sep 17 00:00:00 2001 From: yuin Date: Fri, 14 Jun 2024 21:40:31 +0900 Subject: [PATCH] Fixes #455 --- .github/workflows/test.yaml | 4 ++-- extension/_test/strikethrough.txt | 20 ++++++++++++++++---- extension/strikethrough.go | 3 ++- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index c382846..5009782 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -5,7 +5,7 @@ jobs: strategy: fail-fast: false matrix: - go-version: [1.19.x, 1.20.x] + go-version: [1.21.x, 1.22.x] platform: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.platform }} steps: @@ -16,7 +16,7 @@ jobs: - name: Checkout code uses: actions/checkout@v3 - name: Run lints - uses: golangci/golangci-lint-action@v3 + uses: golangci/golangci-lint-action@v6 with: version: latest if: "matrix.platform == 'ubuntu-latest'" # gofmt linter fails on Windows for CRLF problems diff --git a/extension/_test/strikethrough.txt b/extension/_test/strikethrough.txt index e74f58d..5f37627 100644 --- a/extension/_test/strikethrough.txt +++ b/extension/_test/strikethrough.txt @@ -5,8 +5,6 @@

Hi Hello, world!

//= = = = = = = = = = = = = = = = = = = = = = = =// - - 2 //- - - - - - - - -// This ~~has a @@ -17,11 +15,25 @@ new paragraph~~.

new paragraph~~.

//= = = = = = = = = = = = = = = = = = = = = = = =// - - 3 //- - - - - - - - -// ~Hi~ Hello, world! //- - - - - - - - -//

Hi Hello, world!

//= = = = = = = = = = = = = = = = = = = = = = = =// + +4: Three or more tildes do not create a strikethrough +//- - - - - - - - -// +This will ~~~not~~~ strike. +//- - - - - - - - -// +

This will ~~~not~~~ strike.

+//= = = = = = = = = = = = = = = = = = = = = = = =// + +5: Leading three or more tildes do not create a strikethrough, create a code block +//- - - - - - - - -// +~~~Hi~~~ Hello, world! +//- - - - - - - - -// +
+//= = = = = = = = = = = = = = = = = = = = = = = =// + + diff --git a/extension/strikethrough.go b/extension/strikethrough.go index fbb099f..9fc0bec 100644 --- a/extension/strikethrough.go +++ b/extension/strikethrough.go @@ -47,9 +47,10 @@ func (s *strikethroughParser) Parse(parent gast.Node, block text.Reader, pc pars before := block.PrecendingCharacter() line, segment := block.PeekLine() node := parser.ScanDelimiter(line, before, 1, defaultStrikethroughDelimiterProcessor) - if node == nil { + if node == nil || node.OriginalLength > 2 || before == '~' { return nil } + node.Segment = segment.WithStop(segment.Start + node.OriginalLength) block.Advance(node.OriginalLength) pc.PushDelimiter(node)