MCPcopy Index your code
hub / github.com/deepnote/deepnote / isPercentContent

Function isPercentContent

packages/convert/src/format-detection.ts:53–82  ·  view source on GitHub ↗
(content: string)

Source from the content-addressed store, hash-verified

51
52/** Check if file content is percent format */
53export function isPercentContent(content: string): boolean {
54 // Percent format files have '# %%' cell markers at the start of lines
55 // We need to check that the marker is not inside a triple-quoted string
56 // (e.g., module docstrings at the beginning of the file)
57 const lines = content.split('\n')
58 let inTripleQuote = false
59 let quoteChar = ''
60
61 for (const line of lines) {
62 // Check for triple quote toggles
63 for (const q of ['"""', "'''"]) {
64 let idx = line.indexOf(q, 0)
65 while (idx !== -1) {
66 if (!inTripleQuote) {
67 inTripleQuote = true
68 quoteChar = q
69 } else if (quoteChar === q) {
70 inTripleQuote = false
71 }
72 idx = line.indexOf(q, idx + 3)
73 }
74 }
75
76 // Check for cell marker outside triple quotes
77 if (!inTripleQuote && /^# %%/.test(line)) {
78 return true
79 }
80 }
81 return false
82}
83
84/**
85 * Detects the notebook format from filename and optionally content.

Callers 4

classifyPyFileFunction · 0.90
convertFunction · 0.90
detectFormatFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected