Welcome to mirror list, hosted at ThFree Co, Russian Federation.

table_header_row.js « nodes « markdown « behaviors « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6e3c16f0a085d63bc553eff38a070fde96f00c37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* eslint-disable class-methods-use-this */

import TableRow from './table_row';
import { HIGHER_PARSE_RULE_PRIORITY } from '../constants';

const CENTER_ALIGN = 'center';

// Transforms generated HTML back to GFM for Banzai::Filter::MarkdownFilter
export default class TableHeaderRow extends TableRow {
  get name() {
    return 'table_header_row';
  }

  get schema() {
    return {
      content: 'table_cell+',
      parseDOM: [
        {
          tag: 'thead tr',
          priority: HIGHER_PARSE_RULE_PRIORITY,
        },
      ],
      toDOM: () => ['tr', 0],
    };
  }

  toMarkdown(state, node) {
    const cellWidths = super.toMarkdown(state, node);

    state.flushClose(1);

    state.write('|');
    node.forEach((cell, _, i) => {
      if (i) state.write('|');

      state.write(cell.attrs.align === CENTER_ALIGN ? ':' : '-');
      state.write(state.repeat('-', cellWidths[i]));
      state.write(cell.attrs.align === CENTER_ALIGN || cell.attrs.align === 'right' ? ':' : '-');
    });
    state.write('|');

    state.closeBlock(node);
  }
}