<commit_before>import { findChild } from '../util/domHelpers'
import { getLabel } from '../../shared/nodeHelpers'

export default class SupplementaryFileConverter {
  get type () { return 'supplementary-file' }

  get tagName () { return 'supplementary-material' }

  import (el, node, importer) {
    let $$ = importer.$$
    let labelEl = findChild(el, 'label')
    let captionEl = findChild(el, 'caption')
    // create a new caption element
    if (!captionEl) {
      captionEl = $$('caption')
    }
    // there must be at least one paragraph
    if (!captionEl.find('p')) {
      captionEl.append($$('p'))
    }
    // drop everything than 'p' from caption
    // TODO: use the node schema to decide which
    // elements to drop
    let captionContent = captionEl.children
    for (let idx = captionContent.length - 1; idx >= 0; idx--) {
      let child = captionContent[idx]
      if (child.tagName !== 'p') {
        captionEl.removeAt(idx)
      }
    }
    if (labelEl) {
      node.label = labelEl.text()
    }
    node.href = el.getAttribute('xlink:href')
    node.legend = importer.convertElement(captionEl).id
  }

  export (node, el, exporter) {
    let $$ = exporter.$$
    let doc = node.getDocument()
    el.attr('xlink:href', node.href)
    let label = getLabel(node)
    if (label) {
      el.append($$('label').text(label))
    }
    if (node.legend && node.legend.length > 0) {
      el.append(
        exporter.convertNode(doc.get(node.legend))
      )
    }<commit_msg>Import and export supplement ary-matirial attributes.<commit_after>import { findChild } from '../util/domHelpers'
import { getLabel } from '../../shared/nodeHelpers'

export default class SupplementaryFileConverter {
  get type () { return 'supplementary-file' }

  get tagName () { return 'supplementary-material' }

  import (el, node, importer) {
    let $$ = importer.$$
    let labelEl = findChild(el, 'label')
    let captionEl = findChild(el, 'caption')
    // create a new caption element
    if (!captionEl) {
      captionEl = $$('caption')
    }
    // there must be at least one paragraph
    if (!captionEl.find('p')) {
      captionEl.append($$('p'))
    }
    // drop everything than 'p' from caption
    // TODO: use the node schema to decide which
    // elements to drop
    let captionContent = captionEl.children
    for (let idx = captionContent.length - 1; idx >= 0; idx--) {
      let child = captionContent[idx]
      if (child.tagName !== 'p') {
        captionEl.removeAt(idx)
      }
    }
    if (labelEl) {
      node.label = labelEl.text()
    }
    node.href = el.getAttribute('xlink:href')
    node.mimetype = el.getAttribute('mimetype')
    node['mime-sub-type'] = el.getAttribute('mime-sub-type')
    node.legend = importer.convertElement(captionEl).id
  }

  export (node, el, exporter) {
    let $$ = exporter.$$
    let doc = node.getDocument()
    el.attr({
      'content-type': 'source-data',
      'mimetype': node.mimetype,
      'mime-sub-type': node['mime-sub-type'],
      'xlink:href': node.href
    })
    let label = getLabel(node)
    if (label) {
      el.append($$('label').text(label))
    }
    if (node.legend && node.legend.length > 0) {
      el.append(
        exporter.convertNode(doc.get(node.legend))
      )
    }
{'fraction_non_alphanumeric': 0.1505047415111655, 'fraction_numerical': 0.0018354236769654328, 'mean_word_length': 2.609271523178808, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5213561', 'n_tokens_mistral': 1075, 'n_tokens_neox': 1024, 'n_words': 254}