├── docs ├── .nojekyll ├── images │ ├── logo.png │ ├── example.png │ ├── rulers1.gif │ ├── wcempty.png │ ├── example1.png │ ├── autoWrapExample.gif │ ├── example-smaller.png │ ├── wholeCommentFalse.png │ ├── wholeCommentTrue.png │ ├── editToggleAutoWrap.png │ ├── vsAutoWrapStatusBar.png │ ├── switch-to-prerelease.png │ ├── toggleAutoWrapCommand.png │ ├── vsc-autowrap-icon-off.png │ ├── vsc-autowrap-icon-on.png │ ├── vsc-autowrap-settings.png │ ├── vscAutoWrapStatusBar.png │ ├── vsc-autowrap-icon-tempon.png │ ├── vsc-autowrap-icon-tempoff.png │ ├── logo.svg │ ├── example.svg │ └── example1.svg ├── specs │ ├── content-types │ │ ├── proto.md │ │ ├── tcl.md │ │ ├── r.md │ │ ├── prolog.md │ │ ├── lean.md │ │ ├── d.md │ │ ├── zig.md │ │ ├── markdown │ │ │ ├── html.md │ │ │ ├── comments.md │ │ │ ├── indented-code-blocks.md │ │ │ ├── tables.md │ │ │ ├── headings.md │ │ │ ├── blockquotes.md │ │ │ ├── linkrefdefs.md │ │ │ ├── footnotes.md │ │ │ ├── paragraphs.md │ │ │ ├── thematic-breaks.md │ │ │ ├── front-matter.md │ │ │ ├── fenced-code-blocks.md │ │ │ └── lists.md │ │ ├── matlab.md │ │ ├── batch-file.md │ │ ├── dart.md │ │ ├── julia.md │ │ ├── yaml.md │ │ ├── lua.md │ │ ├── octave.md │ │ ├── doxygen.md │ │ ├── graphql.md │ │ ├── elixir.md │ │ ├── go.md │ │ ├── html.md │ │ ├── plaintext.md │ │ ├── restructuredtext │ │ │ ├── enumerated-lists.md │ │ │ ├── field-lists.md │ │ │ ├── doctest-blocks.md │ │ │ ├── bullet-lists.md │ │ │ └── literal-blocks.md │ │ ├── dotnet-xmldoc.md │ │ └── python.md │ ├── features │ │ ├── embedded-sections.md │ │ ├── misc.md │ │ ├── double-sentence-spacing.md │ │ ├── tabs.md │ │ ├── special-characters.md │ │ ├── spaces.md │ │ ├── decoration-lines.md │ │ ├── block-comments.md │ │ ├── line-comments.md │ │ └── selections.md │ └── README.md ├── README.md ├── prerelease-versions.md ├── extra-features.md ├── extra.css └── configuration-visual-studio.md ├── do.cmd ├── do ├── vs ├── logo.png ├── Properties │ └── AssemblyInfo.cs ├── source.extension.vsixmanifest ├── RewrapPackage.vsct └── RewrapPackage.cs ├── vscode ├── logo.png ├── .vscodeignore ├── tsconfig.json ├── test │ ├── fixture │ │ └── .vscode │ │ │ └── settings.json │ ├── run.cjs │ └── tests.cjs ├── LICENSE ├── .eslintrc.yml ├── src │ ├── CustomLanguage.ts │ ├── Core.ts │ ├── Extension.ts │ └── Settings.ts └── package.json ├── core ├── Parsing.Comments.fs ├── package.json ├── test │ └── package.json ├── Core.Test.fsproj ├── Native.js ├── Parsing.Language.fs ├── Core.fsproj ├── Types.fs ├── Parsing.SourceCode.fs ├── Parsing.Sgml.fs ├── Block.fs ├── Main.fs ├── Columns.fs ├── Parsing.DocComments.fs ├── Parsers.fs └── Nonempty.fs ├── .config └── dotnet-tools.json ├── .editorconfig ├── .github ├── issue_template.md └── workflows │ └── main.yml ├── .gitignore ├── .vscode ├── specs.code-snippets ├── settings.json ├── tasks.json └── launch.json ├── LICENSE ├── package.json ├── Rewrap.sln ├── mkdocs.yml └── README.md /docs/.nojekyll: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /do.cmd: -------------------------------------------------------------------------------- 1 | @node .config/do.mjs %* 2 | -------------------------------------------------------------------------------- /do: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | node .config/do.mjs "$@" 3 | -------------------------------------------------------------------------------- /vs/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnut/Rewrap/HEAD/vs/logo.png -------------------------------------------------------------------------------- /vscode/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnut/Rewrap/HEAD/vscode/logo.png -------------------------------------------------------------------------------- /docs/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnut/Rewrap/HEAD/docs/images/logo.png -------------------------------------------------------------------------------- /docs/images/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnut/Rewrap/HEAD/docs/images/example.png -------------------------------------------------------------------------------- /docs/images/rulers1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnut/Rewrap/HEAD/docs/images/rulers1.gif -------------------------------------------------------------------------------- /docs/images/wcempty.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnut/Rewrap/HEAD/docs/images/wcempty.png -------------------------------------------------------------------------------- /core/Parsing.Comments.fs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnut/Rewrap/HEAD/core/Parsing.Comments.fs -------------------------------------------------------------------------------- /docs/images/example1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnut/Rewrap/HEAD/docs/images/example1.png -------------------------------------------------------------------------------- /docs/images/autoWrapExample.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnut/Rewrap/HEAD/docs/images/autoWrapExample.gif -------------------------------------------------------------------------------- /docs/images/example-smaller.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnut/Rewrap/HEAD/docs/images/example-smaller.png -------------------------------------------------------------------------------- /docs/images/wholeCommentFalse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnut/Rewrap/HEAD/docs/images/wholeCommentFalse.png -------------------------------------------------------------------------------- /docs/images/wholeCommentTrue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnut/Rewrap/HEAD/docs/images/wholeCommentTrue.png -------------------------------------------------------------------------------- /docs/images/editToggleAutoWrap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnut/Rewrap/HEAD/docs/images/editToggleAutoWrap.png -------------------------------------------------------------------------------- /docs/images/vsAutoWrapStatusBar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnut/Rewrap/HEAD/docs/images/vsAutoWrapStatusBar.png -------------------------------------------------------------------------------- /docs/images/switch-to-prerelease.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnut/Rewrap/HEAD/docs/images/switch-to-prerelease.png -------------------------------------------------------------------------------- /docs/images/toggleAutoWrapCommand.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnut/Rewrap/HEAD/docs/images/toggleAutoWrapCommand.png -------------------------------------------------------------------------------- /docs/images/vsc-autowrap-icon-off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnut/Rewrap/HEAD/docs/images/vsc-autowrap-icon-off.png -------------------------------------------------------------------------------- /docs/images/vsc-autowrap-icon-on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnut/Rewrap/HEAD/docs/images/vsc-autowrap-icon-on.png -------------------------------------------------------------------------------- /docs/images/vsc-autowrap-settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnut/Rewrap/HEAD/docs/images/vsc-autowrap-settings.png -------------------------------------------------------------------------------- /docs/images/vscAutoWrapStatusBar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnut/Rewrap/HEAD/docs/images/vscAutoWrapStatusBar.png -------------------------------------------------------------------------------- /docs/images/vsc-autowrap-icon-tempon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnut/Rewrap/HEAD/docs/images/vsc-autowrap-icon-tempon.png -------------------------------------------------------------------------------- /docs/images/vsc-autowrap-icon-tempoff.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dnut/Rewrap/HEAD/docs/images/vsc-autowrap-icon-tempoff.png -------------------------------------------------------------------------------- /vscode/.vscodeignore: -------------------------------------------------------------------------------- 1 | ** 2 | 3 | # Whitelist 4 | !dist/** 5 | !LICENSE 6 | !logo.png 7 | !package.json 8 | !package-lock.json 9 | !README.md 10 | -------------------------------------------------------------------------------- /docs/specs/content-types/proto.md: -------------------------------------------------------------------------------- 1 | > language: "proto" 2 | 3 | // a b c -> // a b ¦ 4 | // d ¦ // c d ¦ 5 | x x x x x x x x x x 6 | -------------------------------------------------------------------------------- /core/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "module", 3 | "module": "dist/index.js", 4 | "source": "dist/dev/Main.js", 5 | "engines": { 6 | "node": ">=14.x" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /docs/specs/content-types/tcl.md: -------------------------------------------------------------------------------- 1 | > language: "tcl" 2 | 3 | # a b c -> # a b ¦ 4 | # d ¦ # c d ¦ 5 | z y x w z y x w 6 | v u ¦ v u ¦ 7 | -------------------------------------------------------------------------------- /.config/dotnet-tools.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "isRoot": true, 4 | "tools": { 5 | "fable": { 6 | "version": "3.6.2", 7 | "commands": [ 8 | "fable" 9 | ] 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | [*] 2 | end_of_line=lf 3 | guidelines = 90 1px solid 77777799 4 | 5 | [*.{cs,fs}] 6 | indent_style = space 7 | insert_final_newline=true 8 | 9 | [*.cs] 10 | tab_width=4 11 | 12 | [*.fs] 13 | tab_width=2 14 | -------------------------------------------------------------------------------- /docs/specs/content-types/r.md: -------------------------------------------------------------------------------- 1 | > language: "r" 2 | 3 | # a b c -> # a b ¦ 4 | # d ¦ # c d ¦ 5 | 6 | ROxygen comments 7 | 8 | #' a b c -> #' a b ¦ 9 | #' d ¦ #' c d ¦ 10 | -------------------------------------------------------------------------------- /.github/issue_template.md: -------------------------------------------------------------------------------- 1 | 7 | -------------------------------------------------------------------------------- /docs/specs/content-types/prolog.md: -------------------------------------------------------------------------------- 1 | > language: "prolog" 2 | 3 | % a b c -> % a b ¦ 4 | % d ¦ % c d ¦ 5 | 6 | /* a b c -> /* a b ¦ 7 | d ¦ c d ¦ 8 | */ ¦ */ ¦ 9 | -------------------------------------------------------------------------------- /core/test/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "prod": "prod.js", 3 | "main": "../dist/dev/Tests.js", 4 | "engines": { 5 | "node": ">=14.x" 6 | }, 7 | "targets": { 8 | "prod": { 9 | "source": "../dist/dev/Tests.js" 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.vs/ 2 | *.csproj.user 3 | /.ionide/ 4 | /.vscode-test/ 5 | /.obj/ 6 | 7 | /node_modules/ 8 | /vscode/node_modules/ 9 | 10 | /core/dist/ 11 | /core/test/prod.js* 12 | /vscode/dist/ 13 | /vscode/README.md 14 | bin/ 15 | obj/ 16 | /venv 17 | .parcel-cache 18 | rewrap-*.vsix 19 | -------------------------------------------------------------------------------- /vscode/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "files": [ "src/Extension.ts" ], 3 | "compilerOptions": { 4 | "module": "commonjs", 5 | "esModuleInterop": true, 6 | "target": "es2019", 7 | "lib": ["ES2019"], 8 | "outDir": "bin", 9 | "sourceMap": true, 10 | "alwaysStrict": true, 11 | "strictNullChecks": true 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /docs/specs/content-types/lean.md: -------------------------------------------------------------------------------- 1 | > language: "lean" 2 | 3 | -- a b c -> -- a b ¦ 4 | -- d ¦ -- c d ¦ 5 | x x x x x x x x x x 6 | /- a b c /- a b ¦ 7 | d ¦ c d ¦ 8 | -/ ¦ -/ ¦ 9 | x x x x x x x x x x 10 | -------------------------------------------------------------------------------- /docs/specs/features/embedded-sections.md: -------------------------------------------------------------------------------- 1 | # Embedded Sections 2 | 3 | > language: "html" 4 | 5 | In eg an HTML file, an embedded script section must behave the same if there is 6 | no closing tag, as if there were one. 7 | 8 | ¦ ¦ 49 | 50 | ¦ ¦ 58 | 59 | ¦ -> ¦ 60 | // one two three // one two ¦ 61 | // four ¦ three // four¦ 62 | ¦ ¦ 63 | -------------------------------------------------------------------------------- /docs/specs/content-types/plaintext.md: -------------------------------------------------------------------------------- 1 | # PlainText 2 | 3 | `plaintext` is the most basic content type. Paragraphs are only separated by blank lines. 4 | This documents also details basic wrapping behavior. 5 | 6 | > language: "plaintext" 7 | 8 | Long lines are split at whitespace and wrapped. 9 | 10 | A long line. -> A long ¦ 11 | ¦ line. ¦ 12 | 13 | Short lines are concatenated and then wrapped as appropriate. 14 | 15 | Three. ¦ -> Three. Short. ¦ 16 | Short. ¦ Lines. ¦ 17 | Lines. ¦ 18 | 19 | Words that are longer than the wrapping width (like URLs) will be put on a new 20 | line but won't be broken up. 21 | 22 | Go to www.example.com -> Go to ¦ 23 | ¦ www.example.com 24 | 25 | Paragraphs are separated by blank lines. 26 | 27 | Foo bar baz. -> Foo bar ¦ 28 | ¦ baz. ¦ 29 | Foo ¦ ¦ 30 | bar. ¦ Foo bar. ¦ 31 | 32 | The indent of all lines is kept as is was: 33 | 34 | one two three one two ¦ 35 | four five six -> three four¦ 36 | seven eight¦ five six ¦ 37 | ¦ seven eight¦ 38 | 39 | ## PlainText-IndentSeparated 40 | 41 | With the `plaintext-indentseparated` processor, a difference in line indent *does* start a 42 | new paragraph. 43 | 44 | > language: plaintext-indentseparated 45 | 46 | Foo bar baz. Foo bar ¦ 47 | Foo ¦ -> baz. ¦ 48 | bar. ¦ Foo bar. ¦ 49 | 50 | Paragraph ¦ Paragraph one.¦ 51 | one. ¦ Paragraph ¦ 52 | Paragraph two. -> two. ¦ 53 | Paragraph three. Paragraph ¦ 54 | ¦ three. ¦ 55 | 56 | Also works with tab characters. In the case of mixed spaces and tabs, it's the *indent 57 | width* that counts, not the actual characters. 58 | 59 | > language: plaintext-indentseparated, tabWidth: 2 60 | 61 | Paragraph one. ¦ Paragraph one. ¦ 62 | -→Paragraph ¦ -> -→Paragraph two.¦ 63 | ··two. ¦ ·Paragraph ¦ 64 | ·Paragraph three. ·three. ¦ 65 | -------------------------------------------------------------------------------- /docs/specs/content-types/markdown/footnotes.md: -------------------------------------------------------------------------------- 1 | > language: "markdown" 2 | 3 | Footnotes are not to be confused with [link reference definitions](linkrefdefs.md). 4 | 5 | Footnotes are not in the CommonMark spec, but are supported by a variety of other flavors 6 | of markdown, including GFM, (PHP) Markdown Extra, MultiMarkdown and Pandoc. These all have 7 | slight differences, so until Rewrap offers support for multiple markdown specs, it tries 8 | to cover everything as best it can. 9 | 10 | A footnote is a section beginning with `[^]:`, where `` is any sequence of 11 | non-whitespace characters, excluding `]` 12 | 13 | `[^fn1]: Footnote` 14 | 15 | Since following paragraphs in the footnote must be indented by at least 4 spaces (see below), a 16 | when a single-line footnote is wrapped, created lines are also indented 4 spaces. 17 | 18 | [^1]: foot note -> [^1]: foot ¦ 19 | ¦ ····note ¦ 20 | 21 | Does a footnote interrupt a paragraph? Pandoc says no but GFM, PHP Markdown, and 22 | MultiMarkdown say yes So we allow it. 23 | 24 | text ¦ text [^1] ¦ 25 | [^1] text ¦ -> text ¦ 26 | [^1]: foot note [^1]: foot ¦ 27 | ¦ note ¦ 28 | 29 | Similarly footnotes can be on consecutive lines 30 | 31 | text ¦ text [^1] ¦ 32 | [^1] [^2] ¦ [^2] ¦ 33 | [^1]: 1 ¦ -> [^1]: 1 ¦ 34 | [^2]: 2 ¦ [^2]: 2 ¦ 35 | 36 | Subsequent paragraphs within the footnote must be indented 4-7 spaces. 8 spaces or more 37 | becomes an indented code block 38 | 39 | [^fn1]: text text [^fn1]: text ¦ 40 | ¦ text ¦ 41 | ····text ¦ -> ¦ 42 | ····text ¦ ····text text¦ 43 | ¦ ¦ 44 | ········code block ········code block 45 | 46 | Unlike [list items](lists.md), there can be any amount of whitespace between the footnote 47 | label and its content; the indent isn't significant. Therefore it's not possible to start 48 | an indented code block on the first line of a footnote. 49 | 50 | [^fn1]: > block quote -> [^fn1]: > block ¦ 51 | ¦ > quote ¦ 52 | -------------------------------------------------------------------------------- /docs/specs/features/spaces.md: -------------------------------------------------------------------------------- 1 | # Spaces 2 | 3 | > language: plaintext 4 | 5 | When some text has multiple spaces between two words, this is preserved... 6 | 7 | Eiusmod ad····ea sunt non -> Eiusmod ad····ea sunt ¦ 8 | reprehenderit elit ¦ non reprehenderit elit¦ 9 | 10 | Unless the split goes over a line boundary. Then all whitespace is removed at that point. 11 | 12 | Et velit velit duis···elit nisi -> Et velit velit duis ¦ 13 | ¦ elit nisi ¦ 14 | 15 | All trailing whitespace is trimmed from every line of any "wrapping block" except for the 16 | last line, where it is preserved. This is the case even if the whitespace goes over the 17 | wrapping column. 18 | 19 | Minim adipisicing voluptate· Minim adipisicing¦ 20 | in ipsum consequat···· -> voluptate in ¦ 21 | ¦ ipsum consequat···· 22 | 23 | ## At the end of a line 24 | 25 | Two spaces at the end of a line preserves the line break after it. This comes 26 | from Markdown and should work for any content. 27 | 28 | > language: "plaintext" 29 | 30 | Foo bar.·· ¦ -> Foo bar.·· ¦ 31 | Baz foo ¦ Baz foo bar ¦ 32 | bar baz. ¦ baz. ¦ 33 | 34 | > language: "markdown" 35 | 36 | Foo bar.·· ¦ -> Foo bar.·· ¦ 37 | Baz foo ¦ Baz foo bar ¦ 38 | bar baz. ¦ baz. ¦ 39 | 40 | > language: "latex" 41 | 42 | Foo bar.·· ¦ -> Foo bar.·· ¦ 43 | Baz foo ¦ Baz foo bar ¦ 44 | bar baz. ¦ baz. ¦ 45 | 46 | > language: "csharp" 47 | 48 | /// ¦ /// ¦ 49 | /// Foo bar.·· ¦ -> /// Foo bar.·· ¦ 50 | /// Baz foo ¦ /// Baz foo bar ¦ 51 | /// bar baz. ¦ /// baz. ¦ 52 | /// ¦ /// ¦ 53 | 54 | > language: "go" 55 | 56 | // Foo bar.·· ¦ -> // Foo bar.·· ¦ 57 | // Baz foo ¦ // Baz foo bar ¦ 58 | // bar baz. ¦ // baz. ¦ 59 | 60 | > language: "powershell" 61 | 62 | <# ¦ <# ¦ 63 | Foo bar.·· ¦ -> Foo bar.·· ¦ 64 | Baz foo ¦ Baz foo bar ¦ 65 | bar baz. ¦ baz. ¦ 66 | #> ¦ #> ¦ 67 | 68 | > language: "rst" 69 | 70 | Foo bar.·· ¦ -> Foo bar.·· ¦ 71 | Baz foo ¦ Baz foo bar ¦ 72 | bar baz. ¦ baz. ¦ 73 | -------------------------------------------------------------------------------- /docs/specs/content-types/restructuredtext/enumerated-lists.md: -------------------------------------------------------------------------------- 1 | # reStructuredText: Enumerated lists 2 | 3 | Enumerated (or numbered) lists behave similarly to [bullet lists](bullet-lists.md). The 4 | rules for list item markers are more complex than for example markdown, however. 5 | 6 | The marker format for items can be `X.`, `X)` or `(X)` where `X` is the enumerator. The 7 | various accepted emumerators are given below. 8 | 9 | > language: "reStructuredText" 10 | 11 | Arabic numerals: 1, 2, 3 ... (no upper limit in RST, though we have the limit of a signed 12 | int32). 13 | 14 | 1) item one text 1) item one ¦ 15 | 2) item ¦ -> text ¦ 16 | two ¦ 2) item two ¦ 17 | 18 | 999999998) item one text 999999998) item one ¦ 19 | 999999999) item ¦ -> text ¦ 20 | two ¦ 999999999) item two ¦ 21 | 22 | Letters: A ,B, C ... Z. Upper or lower-case, but cannot mix case within a list. 23 | 24 | A. item one text A. item one ¦ 25 | B. item ¦ -> text ¦ 26 | two ¦ B. item two ¦ 27 | 28 | a. item one text a. item one ¦ 29 | b. item ¦ -> text ¦ 30 | two ¦ b. item two ¦ 31 | 32 | Roman numerals: I, II, III, IV ... MMMMCMXCIX (4999). Again can be upper or lower case, 33 | but can't be mixed. 34 | 35 | (i) item one text (i) item one ¦ 36 | (ii) item ¦ -> text ¦ 37 | two ¦ (ii) item two ¦ 38 | 39 | (MMMMCMXCVIII) item one text (MMMMCMXCVIII) item one ¦ 40 | (MMMMCMXCIX) item ¦ -> text ¦ 41 | two ¦ (MMMMCMXCIX) item two ¦ 42 | 43 | ## Auto enumerator 44 | 45 | A `#` can be used in place of an enumerator. 46 | 47 | #. item one text #. item one ¦ 48 | #. item ¦ -> text ¦ 49 | two ¦ #. item two ¦ 50 | 51 | ## Validation 52 | 53 | While enumerated lists don't have to start with "1" or equivalent, following items must 54 | follow sequentially ("2", "3" etc). If they don't, then they are not considered part of 55 | the same list. 56 | 57 | If there are blank lines between list items, this has no effect on wrapping. But if there 58 | are no blank lines, the whole text is considered a normal paragraph instead. 59 | 60 | This rule is not yet enfored in Rewrap. 61 | -------------------------------------------------------------------------------- /vscode/src/CustomLanguage.ts: -------------------------------------------------------------------------------- 1 | import JSON from 'json5' 2 | import vscode from 'vscode' 3 | import {CustomMarkers, noCustomMarkers} from './Core' 4 | 5 | const getConfig = (getText, path) => { 6 | let config = {line: null, block: null} 7 | let warnings: string[] = [], error 8 | try { 9 | const c = JSON.parse(getText(path)).comments 10 | if (c) { 11 | // 'line' must be a string or null. 12 | if (typeof c.lineComment === 'string') config.line = c.lineComment 13 | else warnings.push("lineComment not a string.") 14 | // 'block' must be an array of 2 strings or null. 15 | if (Array.isArray(c.blockComment) && c.blockComment.length > 1) 16 | config.block = c.blockComment.slice(0, 2) 17 | else warnings.push("blockComment not a length-2 array.") 18 | } 19 | else warnings.push("No comments block found.") 20 | } 21 | catch (err) { error = err } 22 | if (error || warnings.length) { 23 | console.info(`Inspecting JSON file ${path}`) 24 | if (error) console.error(error.message) 25 | warnings.forEach(w => console.warn(w)) 26 | } 27 | return config 28 | } 29 | 30 | type Cache = Record 31 | 32 | /** Iterates through all extensions and populates the cache with mappings for each found 33 | * language id to a path to a configuration file. */ 34 | function createCache (exts) : Cache { 35 | const addConfigFiles = (cache, ext: vscode.Extension) => { 36 | try { 37 | let obj = ext.packageJSON 38 | if ((obj = obj.contributes) && (obj = obj.languages)) { 39 | for (const l of obj) { 40 | if (!l.id) continue 41 | if (l.configuration) { 42 | const confPath = ext.extensionPath + '/' + l.configuration 43 | cache[l.id] = confPath 44 | } 45 | } 46 | } 47 | } 48 | catch (err) { 49 | console.error(err.message) 50 | } 51 | return cache 52 | } 53 | 54 | return exts.reduce(addConfigFiles, {}) 55 | } 56 | 57 | /* Can take exts & getFileText mocks for testing */ 58 | export default function (exts?, getFileText?) { 59 | exts = exts || vscode.extensions.all 60 | if (!exts.length) 61 | console.warn("`vscode.extensions.all` returned an empty array. Something is wrong.") 62 | if (!getFileText) { 63 | try { getFileText = require('fs').readFileSync } 64 | catch { getFileText = () => "" } 65 | } 66 | 67 | let cache 68 | return lang => { 69 | cache = cache || createCache(exts) 70 | 71 | if (typeof cache[lang] === 'string') { 72 | const config = getConfig(getFileText, cache[lang]) 73 | cache[lang] = (config.line || config.block) ? 74 | {line: config.line, block: config.block || ["", ""]} : noCustomMarkers 75 | } 76 | else if (!cache[lang]) cache[lang] = noCustomMarkers 77 | return cache[lang] 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /mkdocs.yml: -------------------------------------------------------------------------------- 1 | site_name: Rewrap 2 | site_url: https://dnut.github.io/Rewrap/ 3 | repo_url: https://github.com/dnut/rewrap 4 | site_dir: .obj/docsite 5 | strict: true 6 | theme: 7 | name: null 8 | custom_dir: ../mkdocs-material/material 9 | language: en 10 | font: 11 | text: Nunito 12 | code: JetBrains Mono 13 | features: 14 | - toc.integrate 15 | - content.tabs.link 16 | favicon: images/logo.svg 17 | logo: images/logo.svg 18 | icon: null 19 | palette: 20 | - media: "(prefers-color-scheme: light)" 21 | scheme: default 22 | toggle: 23 | icon: material/toggle-switch-off-outline 24 | name: Switch to dark mode 25 | - media: "(prefers-color-scheme: dark)" 26 | scheme: slate 27 | toggle: 28 | icon: material/toggle-switch 29 | name: Switch to light mode 30 | extra_css: 31 | - extra.css 32 | plugins: 33 | - search: 34 | separator: '[\s\-\.]+' 35 | markdown_extensions: 36 | - admonition 37 | - pymdownx.extra 38 | - pymdownx.highlight: 39 | use_pygments: true 40 | - pymdownx.snippets: 41 | check_paths: true 42 | - pymdownx.superfences 43 | - pymdownx.tabbed: 44 | alternate_style: true 45 | nav: 46 | - 'Getting Started': README.md 47 | - configuration.md 48 | - extra-features.md 49 | - 'Specs': 50 | - specs/README.md 51 | - 'Features': 52 | - specs/features/line-comments.md 53 | - specs/features/block-comments.md 54 | - specs/features/decoration-lines.md 55 | - specs/features/selections.md 56 | - specs/features/embedded-sections.md 57 | - specs/features/double-sentence-spacing.md 58 | - specs/features/tabs.md 59 | - specs/features/spaces.md 60 | - specs/features/special-characters.md 61 | - specs/features/misc.md 62 | - 'Content Types': 63 | - specs/content-types/dotnet-xmldoc.md 64 | - specs/content-types/batch-file.md 65 | - specs/content-types/d.md 66 | - specs/content-types/dart.md 67 | - specs/content-types/doxygen.md 68 | - specs/content-types/elixir.md 69 | - specs/content-types/go.md 70 | - specs/content-types/graphql.md 71 | - specs/content-types/html.md 72 | - specs/content-types/javadoc.md 73 | - specs/content-types/julia.md 74 | - specs/content-types/latex.md 75 | - specs/content-types/lean.md 76 | - specs/content-types/lua.md 77 | - specs/content-types/markdown/_markdown.md 78 | - specs/content-types/matlab.md 79 | - specs/content-types/octave.md 80 | - specs/content-types/plaintext.md 81 | - specs/content-types/powershell.md 82 | - specs/content-types/prolog.md 83 | - specs/content-types/proto.md 84 | - specs/content-types/python.md 85 | - specs/content-types/r.md 86 | - specs/content-types/restructuredtext/_restructuredtext.md 87 | - specs/content-types/tcl.md 88 | - specs/content-types/yaml.md 89 | -------------------------------------------------------------------------------- /docs/specs/features/decoration-lines.md: -------------------------------------------------------------------------------- 1 | # Decoration Lines 2 | 3 | Decoration lines are lines of just symbols with no text, that are sometimes used 4 | in comment blocks. 5 | 6 | > language: "java" 7 | 8 | ## Line comments ## 9 | 10 | A "decoration line" is defined as a line where the content after the comment 11 | marker (eg //): 12 | 1. Is not just whitespace 13 | 2. Does not contain any text 14 | 3. Has no preceding whitespace (between the comment marker and the content) 15 | 16 | We need to handle these as a specially, in the case that reformat is on. With 17 | reformat on, the whitespace between the comment marker and content is 18 | normally normalized to one space. But these lines need to be preserved as they 19 | are, with no extra space added. 20 | 21 | //////// ¦ -> //////// ¦ -or- //////// ¦ 22 | // a ¦ // a ¦ // a ¦ 23 | //------ ¦ //------ ¦ //------ ¦ 24 | 25 | If there is whitespace between the comment marker and the decoration symbols, 26 | then that line is treated like the rest of the markdown content - as a 27 | non-wrapping line - but the indent is preserved in the case of reformat off and 28 | normalized in the case of reformat on. 29 | 30 | 31 | ## Block comments ## 32 | 33 | A decoration line is defined as a line which: 34 | 1. Is the first line of the comment, and 35 | 1) Has no text after the start-comment marker. 36 | 2) Has no whitespace between the start-comment marker and the rest of the line. 37 | 2. Or, contains the end-comment marker and contains no text before it 38 | 3. Or, contains no text, and 39 | 1) Has more than one non-whitespace character 40 | 2) Has no whitespace between a conventional line prefix character for the 41 | type of comment block (eg `*` for c-style comments), and the rest of the 42 | line 43 | 3) Has a lesser indent than the tail text indent 44 | 45 | Decoration lines in block comments are output exactly as input. There may be 46 | other decoration lines in the comment that are not detected as such lines but 47 | it doesn't matter because in these cases they still won't be wrapped and their 48 | indent won't be adjusted. 49 | 50 | /*text */ ¦ -> /*text */ ¦ -or- /* text */¦ 51 | /*-*-* */ ¦ /*-*-* */ ¦ /*-*-* */ ¦ 52 | 53 | /********** ¦ -> /********** ¦ -or- /********** ¦ 54 | * aaa ¦ * aaa bbb ¦ * aaa bbb ¦ 55 | * bbb ¦ ********** ¦ ********** ¦ 56 | ********** ¦ * ccccc ¦ * ccccc ¦ 57 | * ccccc ddddd * ddddd ¦ * ddddd ¦ 58 | ---------- ¦ ---------- ¦ ---------- ¦ 59 | **********/¦ **********/¦ **********/¦ 60 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | For VS Code, 8 | Open VSX and 9 | 10 | Visual Studio. 11 | Latest stable version 1.16.3 / pre-release 17.x / 12 | changelog 13 | 14 | 15 | 16 | Rewrap Revived 17 | 18 | Rewrap Revived is a Visual Studio and VS Code extension that is used to hard-wrap code 19 | comments to a configured maximium line length. This is a fork of the unmaintained 20 | [Rewrap](https://github.com/stkb/Rewrap) extension by Steve Baker 21 | ([@stkb](https://github.com/stkb)). 22 | 23 | 24 | 25 | The main Rewrap command is: **Rewrap Comment / Text**, by default bound to 26 | `Alt+Q`. With the cursor in a comment block, hit this to re-wrap the contents to the 27 | [specified wrapping column](https://dnut.github.io/Rewrap/configuration/#wrapping-column). 28 | 29 | ## Features 30 | 31 | * Re-wrap comment blocks in many languages, with per-language settings. 32 | * Smart handling of contents, including Java-/JS-/XMLDoc tags and code examples. 33 | * Can select lines to wrap or multiple comments/paragraphs at once (even the whole 34 | document). 35 | * Also works with Markdown documents, LaTeX or any kind of plain text file. 36 | 37 | The contents of comments are usually parsed as markdown, so you can use lists, code 38 | samples (which are untouched) etc: 39 | 40 | 41 | 42 | 43 | See the docs site for more info. 44 | 45 | ## Installation 46 | 47 | Rewrap Revived is available in both the 48 | [Microsoft marketplace](https://marketplace.visualstudio.com/items?itemName=dnut.rewrap-revived) 49 | and the [OpenVSX marketplace](https://open-vsx.org/extension/dnut/rewrap-revived). 50 | 51 | **Please install the pre-release version**. That way, you can identify any bugs and report 52 | them, so they don't make their way into the stable release. If you *do* observe a bug, then you 53 | can switch to the stable release, and rest assured that the bug will not be introduced there, 54 | since you have reported the issue (unless of course, it is already present in both releases). 55 | -------------------------------------------------------------------------------- /docs/specs/content-types/dotnet-xmldoc.md: -------------------------------------------------------------------------------- 1 | # .Net XmlDoc 2 | 3 | .Net xml doc comments are parsed as xml/html instead of markdown, so wrapping and newlines 4 | follow the rules for html instead. This keeps tags separated on new lines. 5 | 6 | > language: "csharp" 7 | 8 | /// What the method -> /// What the ¦ 9 | /// does ¦ /// method does ¦ 10 | /// ¦ /// ¦ 11 | /// The s param ¦ /// The s param ¦ 12 | /// ¦ /// ¦ 13 | /// ¦ /// ¦ 14 | /// Extended info. ¦ /// Extended info. Text ¦ 15 | /// Text text text. ¦ /// text text. ¦ 16 | /// ¦ /// ¦ 17 | 18 | > language: "fsharp" 19 | 20 | /// What the method -> /// What the ¦ 21 | /// does ¦ /// method does ¦ 22 | /// ¦ /// ¦ 23 | /// The s param ¦ /// The s param ¦ 24 | /// ¦ /// ¦ 25 | /// ¦ /// ¦ 26 | /// Extended info. ¦ /// Extended info. Text ¦ 27 | /// Text text text. ¦ /// text text. ¦ 28 | /// ¦ /// ¦ 29 | 30 | > language: "vb" 31 | 32 | ''' What the method -> ''' What the ¦ 33 | ''' does ¦ ''' method does ¦ 34 | ''' ¦ ''' ¦ 35 | ''' The s param ¦ ''' The s param ¦ 36 | ''' ¦ ''' ¦ 37 | ''' ¦ ''' ¦ 38 | ''' Extended info. ¦ ''' Extended info. Text ¦ 39 | ''' Text text text. ¦ ''' text text. ¦ 40 | ''' ¦ ''' ¦ 41 | 42 | There is however, an extra rule. Line breaks are only preserved before/after certain 43 | "block tags". The list of these tags is: *code, description, example, exception, include, 44 | inheritdoc, list, listheader, item, para, param, permission, remarks, seealso, summary, 45 | term, typeparam, typeparamref, returns, value*. 46 | 47 | All other tags, eg `` are treated as inline tags and will always be wrapped inline with 48 | the surrounding text. 49 | 50 | > language: "csharp" 51 | 52 | /// Text ¦ /// Text TypeName text ¦ 53 | /// TypeName ¦ -> /// text. ¦ 54 | /// text text. ¦ ¦ 55 | -------------------------------------------------------------------------------- /core/Parsing.Sgml.fs: -------------------------------------------------------------------------------- 1 | module internal Parsing.Sgml 2 | 3 | open Prelude 4 | open Line 5 | open Parsing_ 6 | open Block 7 | open Rewrap 8 | open Parsing.Core 9 | open System.Text.RegularExpressions 10 | 11 | let private markdown = Parsing.Markdown.markdown 12 | 13 | let inline private regex str = 14 | Regex(str, RegexOptions.IgnoreCase) 15 | 16 | let private scriptMarkers = 17 | (regex "