How to use the mjml-validator function in mjml-validator

To help you get started, we’ve selected a few mjml-validator examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mjmlio / mjml / packages / mjml-cli / src / client.js View on Github external
inputs.forEach(i => {
    try {
      let compiled
      switch (inputOpt) {
        case 'm': // eslint-disable-line no-case-declarations
          compiled = { html: migrate(i.mjml, { beautify: true }) }
          break
        case 'v': // eslint-disable-line no-case-declarations
          const mjmlJson = MJMLParser(i.mjml, { components })
          compiled = {
            errors: validate(mjmlJson, { components, initializeType }),
          }
          break
        default:
          compiled = mjml2html(i.mjml, { ...config, filePath: filePath || i.file })
      }

      convertedStream.push({ ...i, compiled })
    } catch (e) {
      EXIT_CODE = 2
      failedStream.push({ file: i.file, error: e })
    }
  })
github mjmlio / mjml / packages / mjml-core / src / MJMLRenderer.js View on Github external
validate () {
    if (this.options.level == "skip") {
      return;
    }

    this.errors = MJMLValidator(this.content)

    if (this.options.level == "strict" && this.errors.length > 0) {
      throw new MJMLValidationError(this.errors)
    }
  }
github mjmlio / mjml / packages / mjml-core / src / index.js View on Github external
title: '',
    forceOWADesktop: get(mjml, 'attributes.owa', 'mobile') === 'desktop',
    lang: get(mjml, 'attributes.lang'),
  }

  const validatorOptions = {
    components,
    initializeType,
  }

  switch (validationLevel) {
    case 'skip':
      break

    case 'strict':
      errors = MJMLValidator(mjml, validatorOptions)

      if (errors.length > 0) {
        throw new ValidationError(
          `ValidationError: \n ${errors
            .map(e => e.formattedMessage)
            .join('\n')}`,
          errors,
        )
      }
      break

    case 'soft':
    default:
      errors = MJMLValidator(mjml, validatorOptions)
      break
  }
github mjmlio / mjml / packages / mjml-core / src / index.js View on Github external
case 'strict':
      errors = MJMLValidator(mjml, validatorOptions)

      if (errors.length > 0) {
        throw new ValidationError(
          `ValidationError: \n ${errors
            .map(e => e.formattedMessage)
            .join('\n')}`,
          errors,
        )
      }
      break

    case 'soft':
    default:
      errors = MJMLValidator(mjml, validatorOptions)
      break
  }

  const mjBody = find(mjml.children, { tagName: 'mj-body' })
  const mjHead = find(mjml.children, { tagName: 'mj-head' })

  const processing = (node, context, parseMJML = identity) => {
    if (!node) {
      return
    }

    const component = initComponent({
      name: node.tagName,
      initialDatas: {
        ...parseMJML(node),
        context,

mjml-validator

mjml-validator

MIT
Latest version published 8 months ago

Package Health Score

91 / 100
Full package analysis

Similar packages