antonWetzel / typst-languagetool

LanguageTool Integration for Typst for spell and grammer check
MIT License
36 stars 9 forks source link

"Loose punctuation mark" (UNLIKELY_OPENING_PUNCTUATION) error when using inline function with `[]` #8

Closed Andrew15-5 closed 7 months ago

Andrew15-5 commented 7 months ago
Listen carefully, it will be on the test.
Listen #[carefully], it will be on the test.
Listen #highlight[carefully], it will be on the test.

image

image

1. Loose punctuation mark. [UNLIKELY_OPENING_PUNCTUATION]

Used 4d48a86 commit.

antonWetzel commented 7 months ago

The [ and ] were converted to "\n\n". This works for caption: [...] or similar, but not for highlight[...].

I changed it to ignore [ and ], but allow replacements for named arguments and seperators for arguments based on the function.

With the rules

{
  "arguments": {
    "caption": {
      "before": "\n\n",
      "after": "\n\n",
    },
  },
  "function": {
    "table": {
      "after_argument": "\n",
    },
  },
}

The source

#table(
    columns: 2,
    [*Name:*], [*Test*],
    [value],   [test],
)

#figure(
    caption: [wow],
    "cool body",
)

This is #highlight[important].

is converted to

Name:
Test
value
test

wow

This is important.
Andrew15-5 commented 7 months ago

So you provided an abstract overview. Looking into the code there is nothing even close to this. But changing this:

            SyntaxKind::LeftBracket | SyntaxKind::RightBracket => {
                output.add_encoded(node.text().into(), String::from("\n\n"));
            },

to this:

            SyntaxKind::LeftBracket | SyntaxKind::RightBracket => {
                output.add_encoded(node.text().into(), String::from(""));
            },

indeed removes the error. But this fix is only for one specific use case...

antonWetzel commented 7 months ago

https://github.com/antonWetzel/typst-languagetool/commit/194682eeea4a4f0ef9836b4e36c674c4a203a24b#diff-d42cae02d6ab6561d7a3d9a4d5538b03cdb33e075dfe41a89e70fd8206d9eaabR183-L187 This changed the behaviour to the default case with output.add_markup(...), which is equalivent to output.add_encoded(..., "").

If the content in the [...] is a seperate paragraph, with rules newlines can be inserted around the content.

Andrew15-5 commented 7 months ago

Great now it doesn't show the error. Thanks.