Skip to content

Commit 4dc9860

Browse files
committed
format
1 parent 51df8ea commit 4dc9860

6 files changed

Lines changed: 21 additions & 22 deletions

File tree

packages/format/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from './lib/format';
1+
export * from "./lib/format";

packages/format/src/lib/docStructure.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ const docEmpty = [
153153
"video",
154154
"slate",
155155
"webwork",
156-
]; const listLike = ["ol", "ul", "dl"];
156+
];
157+
const listLike = ["ol", "ul", "dl"];
157158
const mathDisplay = ["me", "men", "md", "mdn"];
158159
const footnoteLike = ["fn"];
159160
const nestableTags = [
@@ -203,4 +204,3 @@ export const blockTags = [
203204
...nestableTags,
204205
...mathDisplay,
205206
];
206-
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { formatPretext } from './format';
1+
import { formatPretext } from "./format";
22

3-
describe('format', () => {
4-
it('should format pretext content', () => {
5-
const input = '<pretext>sample content</pretext>';
3+
describe("format", () => {
4+
it("should format pretext content", () => {
5+
const input = "<pretext>sample content</pretext>";
66
const result = formatPretext(input);
77
expect(result).toBeDefined();
88
// Add more specific assertions based on expected behavior
99
});
1010

11-
it('should handle empty input', () => {
12-
const result = formatPretext('');
13-
expect(result).toBe('');
11+
it("should handle empty input", () => {
12+
const result = formatPretext("");
13+
expect(result).toBe("");
1414
});
1515
});

packages/format/src/lib/format.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
import { blockTags, lineEndTags, newlineTags, verbatimTags } from "./docStructure";
2-
1+
import {
2+
blockTags,
3+
lineEndTags,
4+
newlineTags,
5+
verbatimTags,
6+
} from "./docStructure";
37

48
// Function to join lines of text, preserving verbatim blocks.
59
function joinLines(fullText: string): string {
@@ -42,15 +46,14 @@ function joinLines(fullText: string): string {
4246
return joinedText;
4347
}
4448

45-
4649
export function formatPretext(
4750
text: string,
4851
options?: {
4952
breakLines?: "few" | "some" | "many";
5053
breakSentences?: boolean;
5154
insertSpaces?: boolean;
5255
tabSize?: number;
53-
}
56+
},
5457
): string {
5558
// set default options
5659
const breakSentences = options?.breakSentences ?? false;
@@ -67,7 +70,7 @@ export function formatPretext(
6770
// start tag can be <tag>, <tag attr="val">, or <tag xmlns="..."> but shouldn't be self closing (no self closing tag would have xmlns in it)
6871
let startTag = new RegExp(
6972
"<" + btag + "(>|(\\s[^\\/]*?)>|(.*xmlns.*?)>)",
70-
"g"
73+
"g",
7174
);
7275
let endTag = new RegExp("<\\/" + btag + ">([\\s\\S]*?[.,!?;:]?)", "g");
7376
allText = allText.replace(startTag, "\n$&\n");
@@ -84,7 +87,6 @@ export function formatPretext(
8487
allText = allText.replace(selfCloseTag, "$&\n");
8588
}
8689

87-
8890
// Set indent character to \t or a number of ss based on editor settings.
8991
let indentChar = "\t";
9092
if (insertSpaces && typeof tabSize === "number") {
@@ -131,7 +133,7 @@ export function formatPretext(
131133
if (breakSentences) {
132134
trimmedLine = trimmedLine.replace(
133135
/\.\s+/g,
134-
".\n" + indentChar.repeat(level)
136+
".\n" + indentChar.repeat(level),
135137
);
136138
}
137139
fixedLines.push(indentChar.repeat(level) + trimmedLine);

packages/vscode-extension/src/lsp-server/formatter-ptx.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function getOptions() {
1515
blankLines: globalSettings.formatter.blankLines,
1616
indentSize: globalSettings.editor.tabSize,
1717
insertSpaces: globalSettings.editor.insertSpaces,
18-
}
18+
};
1919
return options;
2020
}
2121

packages/vscode-extension/src/lsp-server/main.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,7 @@ connection.onDidChangeConfiguration((change) => {
203203
connection.workspace
204204
.getConfiguration(tabSizeConfigSection)
205205
.then((tabSizeConfig) => {
206-
if (
207-
tabSizeConfig &&
208-
globalSettings.editor.tabSize !== tabSizeConfig
209-
) {
206+
if (tabSizeConfig && globalSettings.editor.tabSize !== tabSizeConfig) {
210207
console.log("Tab size changed to", tabSizeConfig);
211208
globalSettings.editor.tabSize = tabSizeConfig;
212209
}

0 commit comments

Comments
 (0)