1. /**
  2. * This module implements `<ref>` and `<references>` extension tag handling
  3. * natively in Parsoid.
  4. * @module ext/Cite
  5. */
  6. 'use strict';
  7. const Ref = require('./Ref.js');
  8. const References = require('./References.js');
  9. const RefProcessor = require('./RefProcessor.js');
  10. /**
  11. * Native Parsoid implementation of the Cite extension
  12. * that ties together `<ref>` and `<references>`.
  13. */
  14. class Cite {
  15. constructor() {
  16. this.config = {
  17. name: 'cite',
  18. domProcessors: {
  19. wt2htmlPostProcessor: RefProcessor,
  20. html2wtPreProcessor: (...args) => this._html2wtPreProcessor(...args),
  21. },
  22. tags: [
  23. {
  24. name: 'ref',
  25. toDOM: Ref.toDOM,
  26. fragmentOptions: {
  27. sealFragment: true,
  28. },
  29. serialHandler: Ref.serialHandler, // FIXME: Rename to toWikitext
  30. lintHandler: Ref.lintHandler,
  31. // FIXME: Do we need (a) domDiffHandler (b) ... others ...
  32. }, {
  33. name: 'references',
  34. toDOM: References.toDOM,
  35. serialHandler: References.serialHandler,
  36. lintHandler: References.lintHandler,
  37. },
  38. ],
  39. styles: [
  40. 'ext.cite.style',
  41. 'ext.cite.styles',
  42. ],
  43. };
  44. }
  45. /**
  46. * html -> wt DOM PreProcessor
  47. *
  48. * This is to reconstitute page-level information from local annotations
  49. * left behind by editing clients.
  50. *
  51. * Editing clients add inserted: true or deleted: true properties to a <ref>'s
  52. * data-mw object. These are no-ops for non-named <ref>s. For named <ref>s,
  53. * - for inserted refs, we might want to de-duplicate refs.
  54. * - for deleted refs, if the primary ref was deleted, we have to transfer
  55. * the primary ref designation to another instance of the named ref.
  56. */
  57. _html2wtPreProcessor(env, body) {
  58. // TODO
  59. }
  60. }
  61. if (typeof module === "object") {
  62. module.exports = Cite;
  63. }