89230a6c14f5b77bf8c5b645f80b82f7e06388c35684ba8d37d622dffe54dd205b78c9d46631e9d38a8558be1ed6e50f97cedf7dbfc5b819d9de8ba54f1ba6 971 B

123456789101112131415161718192021222324
  1. const normalWeightRegexp = /font-weight:\s*normal/;
  2. const blockTagNames = ['P', 'OL', 'UL'];
  3. const isBlockElement = element => {
  4. return element && blockTagNames.includes(element.tagName);
  5. };
  6. const normalizeEmptyLines = doc => {
  7. Array.from(doc.querySelectorAll('br')).filter(br => isBlockElement(br.previousElementSibling) && isBlockElement(br.nextElementSibling)).forEach(br => {
  8. br.parentNode?.removeChild(br);
  9. });
  10. };
  11. const normalizeFontWeight = doc => {
  12. Array.from(doc.querySelectorAll('b[style*="font-weight"]')).filter(node => node.getAttribute('style')?.match(normalWeightRegexp)).forEach(node => {
  13. const fragment = doc.createDocumentFragment();
  14. fragment.append(...node.childNodes);
  15. node.parentNode?.replaceChild(fragment, node);
  16. });
  17. };
  18. export default function normalize(doc) {
  19. if (doc.querySelector('[id^="docs-internal-guid-"]')) {
  20. normalizeFontWeight(doc);
  21. normalizeEmptyLines(doc);
  22. }
  23. }
  24. //# sourceMappingURL=googleDocs.js.map