summaryrefslogtreecommitdiffstats
path: root/index.js
blob: 1a741d044a804413324f64ae63cf947b45f6cdd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var eejs = require('ep_etherpad-lite/node/eejs/');
var Changeset = require("ep_etherpad-lite/static/js/Changeset");

exports.eejsBlock_editbarMenuLeft = function (hook_name, args, cb) {
  args.content = args.content + eejs.require("ep_headline_buttons/templates/editbarButtons.ejs");
  return cb();
}

exports.eejsBlock_styles = function (hook_name, args, cb) {
  args.content = args.content + eejs.require("ep_headline_buttons/templates/editbarButtons_styles.ejs");
  return cb();
}

exports.getLineHTMLForExport = function (hook, ctx) {
  function _analyzeLine(lineAttrs, pool) {
    if (lineAttrs) {
      var opIter = Changeset.opIterator(lineAttrs);
      if (opIter.hasNext()) {
        var op = opIter.next();
        return Changeset.opAttributeValue(op, 'headline_buttons', pool);
      }
    }
  }

  function _getStyle(tag) {
    switch (tag) {
      case 'h1':
        return 'margin: 0; line-height: 1.5em; font-size: 2em';
      case 'h2':
        return 'margin: 0; line-height: 1.5em; font-size: 1.5em';
      case 'h3':
        return 'margin: 0; line-height: 1.5em; font-size: 1.17em';
      case 'h4':
        return 'margin: 0; line-height: 1.5em';
      case 'h5':
        return 'margin: 0; line-height: 1.5em; font-size: 0.83em';
      case 'h6':
        return 'margin: 0; line-height: 1.5em; font-size: 0.75em';
    }

    return '';
  }

  var tag = _analyzeLine(ctx.attribLine, ctx.apool);
  if (tag) {
    var style = _getStyle(tag);
    return "<" + tag + " style=\"" + style + "\">" + ctx.text.substring(1) + "</" + tag + ">";
  }
}