has-lang-evaluate.js 867 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { isXHTML } from '../../core/utils';
  2. function hasValue(value) {
  3. return (value || '').trim() !== '';
  4. }
  5. function hasLangEvaluate(node, options, virtualNode) {
  6. // special case when xml:lang has a value and lang does not
  7. // but the document is not XHTML
  8. const xhtml = typeof document !== 'undefined' ? isXHTML(document) : false;
  9. if (
  10. options.attributes.includes('xml:lang') &&
  11. options.attributes.includes('lang') &&
  12. hasValue(virtualNode.attr('xml:lang')) &&
  13. !hasValue(virtualNode.attr('lang')) &&
  14. !xhtml
  15. ) {
  16. this.data({
  17. messageKey: 'noXHTML'
  18. });
  19. return false;
  20. }
  21. const hasLang = options.attributes.some(name => {
  22. return hasValue(virtualNode.attr(name));
  23. });
  24. if (!hasLang) {
  25. this.data({
  26. messageKey: 'noLang'
  27. });
  28. return false;
  29. }
  30. return true;
  31. }
  32. export default hasLangEvaluate;