11/*
22 * document.ts
33 *
4- * Copyright (C) 2023 by Posit Software, PBC
4+ * Copyright (C) 2023-2024 by Posit Software, PBC
55 * Copyright (c) Microsoft Corporation. All rights reserved.
66 *
77 * Unless you have received this program directly from Posit Software pursuant
@@ -22,50 +22,50 @@ import { makeRange } from 'quarto-core';
2222 * A document in the workspace.
2323 */
2424export interface Document {
25- /**
26- * The uri of the document, as a string.
27- */
28- readonly uri : string ;
29-
30- /**
31- * The uri of the document, as a URI.
32- */
33- readonly $uri ?: URI ;
34-
35- /**
36- * The lanugageId of the document
37- */
38- readonly languageId : string | undefined ;
39-
40- /**
41- * Version number of the document's content.
42- */
43- readonly version : number ;
44-
45- /**
46- * The total number of lines in the document.
47- */
48- readonly lineCount : number ;
49-
50- /**
51- * Get text contents of the document.
52- *
53- * @param range Optional range to get the text of. If not specified, the entire document content is returned.
54- */
55- getText ( range ?: Range ) : string ;
56-
57- /**
58- * Converts an offset in the document into a {@link Position position}.
59- */
60- positionAt ( offset : number ) : Position ;
25+ /**
26+ * The uri of the document, as a string.
27+ */
28+ readonly uri : string ;
29+
30+ /**
31+ * The uri of the document, as a URI.
32+ */
33+ readonly $uri ?: URI ;
34+
35+ /**
36+ * The lanugageId of the document
37+ */
38+ readonly languageId : string | undefined ;
39+
40+ /**
41+ * Version number of the document's content.
42+ */
43+ readonly version : number ;
44+
45+ /**
46+ * The total number of lines in the document.
47+ */
48+ readonly lineCount : number ;
49+
50+ /**
51+ * Get text contents of the document.
52+ *
53+ * @param range Optional range to get the text of. If not specified, the entire document content is returned.
54+ */
55+ getText ( range ?: Range ) : string ;
56+
57+ /**
58+ * Converts an offset in the document into a {@link Position position}.
59+ */
60+ positionAt ( offset : number ) : Position ;
6161}
6262
6363export function getLine ( doc : Document , line : number ) : string {
64- return doc . getText ( makeRange ( line , 0 , line , Number . MAX_VALUE ) ) . replace ( / \r ? \n $ / , '' ) ;
64+ return doc . getText ( makeRange ( line , 0 , line , Number . MAX_VALUE ) ) . replace ( / \r ? \n $ / , '' ) ;
6565}
6666
6767export function getDocUri ( doc : Document ) : URI {
68- return doc . $uri ?? URI . parse ( doc . uri ) ;
68+ return doc . $uri ?? URI . parse ( doc . uri ) ;
6969}
7070
7171
@@ -100,6 +100,7 @@ export function isQuartoYaml(doc: Document) {
100100 return (
101101 doc . languageId === kYamlLanguageId &&
102102 ( doc . uri . match ( / _ q u a r t o ( - .* ?) ? \. y a ? m l $ / ) ||
103+ doc . uri . match ( / _ b r a n d \. y a ? m l $ / ) ||
103104 doc . uri . match ( / _ m e t a d a t a \. y a ? m l $ / ) ||
104105 doc . uri . match ( / _ e x t e n s i o n \. y a ? m l $ / ) )
105106 ) ;
@@ -113,7 +114,7 @@ const kRegExYAML =
113114 / ( ^ ) ( - - - [ \t ] * [ \r \n ] + (? ! [ \t ] * [ \r \n ] + ) [ \W \w ] * ?[ \r \n ] + (?: - - - | \. \. \. ) ) ( [ \t ] * ) $ / gm;
114115
115116export function isQuartoDocWithFormat ( doc : Document | string , format : string ) {
116- if ( typeof ( doc ) !== "string" ) {
117+ if ( typeof ( doc ) !== "string" ) {
117118 if ( isQuartoDoc ( doc ) ) {
118119 doc = doc . getText ( ) ;
119120 } else {
@@ -125,7 +126,7 @@ export function isQuartoDocWithFormat(doc: Document | string, format: string) {
125126 if ( match ) {
126127 const yaml = match [ 0 ] ;
127128 return (
128- ! ! yaml . match ( new RegExp ( "^format:\\s+" + format + "\\s*$" , "gm" ) ) ||
129+ ! ! yaml . match ( new RegExp ( "^format:\\s+" + format + "\\s*$" , "gm" ) ) ||
129130 ! ! yaml . match ( new RegExp ( "^[ \\t]*" + format + ":\\s*(default)?\\s*$" , "gm" ) )
130131 ) ;
131132 }
0 commit comments