<commit_before>import { InlineSyntaxNode } from './InlineSyntaxNode'
import { OutlineSyntaxNode } from './OutlineSyntaxNode'
import { OutlineSyntaxNodeContainer } from './OutlineSyntaxNodeContainer'
import { Heading } from './Heading'
import { ReferenceToTableOfContentsEntry } from './ReferenceToTableOfContentsEntry'
import { insertFootnoteBlocksAndAssignFootnoteReferenceNumbers } from './insertFootnoteBlocksAndAssignFootnoteReferenceNumbers'
import { concat } from '../CollectionHelpers'


export class UpDocument extends OutlineSyntaxNodeContainer {
  // Returns an UpDocument object with:
  //
  // 1. Footnotes extracted into footnote blocks
  // 2. A table of contents produced from `children`
  // 3. Internal references associated with the apprioriate table of contents entries
  //
  // Responsibilities 1 and 3 mutate the `children` argument (and its descendants).
  static create(children: OutlineSyntaxNode[]): UpDocument {
    // Unfortunately, this process of producing a ready-to-use UpDocument has become a tad scattered.
    // It needs to be revisited.

    // First, let's create our table of contents. It's up to each outline syntax node whether to allow
    // its descendants to be referenced by the table of contents. Some don't (e.g. blockquotes).
    const tableOfContents =
      UpDocument.TableOfContents.createAndAssociateEntriesWithTheirReferences(children)

    // Alright! We now have everything we need to produce our document!
    const document = new UpDocument(children, tableOfContents)

    // Finally, if there are any footnotes, they still need their reference numbers, and they still
    // need to be extracted into blocks. Let's do it.
    insertFootnoteBlocksAndAssignFootnoteReferenceNumbers(document)

    // Whew. We're done!
    return document
  }

  constructor(children: OutlineSyntaxNode[], public tableOfContents = new UpDocument.TableOfContents()) {
    super(children)
  }
}


export namespace UpDocument {
  export class TableOfContents {
    // Returns a TableOfContents object with entries from `documentChildren`.
    //
    // If there are references to table of contents entries within `documentChildren`, they are
    // associated with the appropriate entries (mutating the references).
    //
    // This methods also mutates the entries themselves, assigning them their table of contents
    // ordinals.
    static createAndAssociateEntriesWithTheirReferences(documentChildren: OutlineSyntaxNode[]): TableOfContents {
      const entries = TableOfContents.getEntries(documentChildren)

      //
      for (let i = 0; i < entries.length; i++) {
        entries[i].ordinalInTableOfContents = i + 1
      }
<commit_msg>Consistently use backticks in comments<commit_after>import { InlineSyntaxNode } from './InlineSyntaxNode'
import { OutlineSyntaxNode } from './OutlineSyntaxNode'
import { OutlineSyntaxNodeContainer } from './OutlineSyntaxNodeContainer'
import { Heading } from './Heading'
import { ReferenceToTableOfContentsEntry } from './ReferenceToTableOfContentsEntry'
import { insertFootnoteBlocksAndAssignFootnoteReferenceNumbers } from './insertFootnoteBlocksAndAssignFootnoteReferenceNumbers'
import { concat } from '../CollectionHelpers'


export class UpDocument extends OutlineSyntaxNodeContainer {
  // Returns an `UpDocument` object with:
  //
  // 1. Footnotes extracted into footnote blocks
  // 2. A table of contents produced from `children`
  // 3. Internal references associated with the apprioriate table of contents entries
  //
  // Responsibilities 1 and 3 mutate the `children` argument (and its descendants).
  static create(children: OutlineSyntaxNode[]): UpDocument {
    // Unfortunately, this process of producing a ready-to-use UpDocument has become a tad scattered.
    // It needs to be revisited.

    // First, let's create our table of contents. It's up to each outline syntax node whether to allow
    // its descendants to be referenced by the table of contents. Some don't (e.g. blockquotes).
    const tableOfContents =
      UpDocument.TableOfContents.createAndAssociateEntriesWithTheirReferences(children)

    // Alright! We now have everything we need to produce our document!
    const document = new UpDocument(children, tableOfContents)

    // Finally, if there are any footnotes, they still need their reference numbers, and they still
    // need to be extracted into blocks. Let's do it.
    insertFootnoteBlocksAndAssignFootnoteReferenceNumbers(document)

    // Whew. We're done!
    return document
  }

  constructor(children: OutlineSyntaxNode[], public tableOfContents = new UpDocument.TableOfContents()) {
    super(children)
  }
}


export namespace UpDocument {
  export class TableOfContents {
    // Returns a `TableOfContents` object with entries from `documentChildren`.
    //
    // If there are references to table of contents entries within `documentChildren`, they are
    // associated with the appropriate entries (mutating the references).
    //
    // This methods also mutates the entries themselves, assigning them their table of contents
    // ordinals.
    static createAndAssociateEntriesWithTheirReferences(documentChildren: OutlineSyntaxNode[]): TableOfContents {
      const entries = TableOfContents.getEntries(documentChildren)

      //
      for (let i = 0; i < entries.length; i++) {
        entries[i].ordinalInTableOfContents = i + 1
      }

{'fraction_non_alphanumeric': 0.07668086682719022, 'fraction_numerical': 0.0025930727912576402, 'mean_word_length': 3.913557779799818, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3602007', 'n_tokens_mistral': 1385, 'n_tokens_neox': 1306, 'n_words': 502}