summaryrefslogtreecommitdiff
path: root/help3/xhpeditor/autocomplete.js
blob: 2af035fc452a96ba42aa5956537d48e74d1b513f (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
 */


// Here we define the schema for XHP, for the auto-completion

var xhptags = {
    "!top": ["helpdocument"],
    helpdocument: {
        children: ["meta", "body"],
        attrs: {version: ["1.0"]},
    },
    meta: {
        children: ["topic", "history"],
        attrs: {localise: ["false"]},
    },
    topic: {
        children: ["title", "bookmark", "filename"],
        attrs: {id: null, indexer: ["exclude", "include"]}
    },
    history: {
        children: ["created", "lastedited"]
    },
    created: {
        attrs: {date: null}
    },
    lastedited: {
        attrs: {date: null}
    },
    body: {
        attrs: {name: null, localize: ["false"]},
        children: ["section", "paragraph", "table", "comment", "bookmark", "switch", "embed", "list", "sort"]
    },
    section: {
        attrs: {id: null, localise: ["false"]},
        children: ["section", "paragraph", "table", "list", "comment", "embed", "switch", "sort"]
    },
    paragraph: {
        attrs: {'xml-lang': null, role: null, level: null, id: null, l10n: null, oldref: null, localize: ["false"]},
        children: ["image", "embedvar", "br", "emph", "help-id-missing", "item", "link", "switchinline", "variable", "ahelp", "object", "bookmark"]
    },
    image: {
        attrs: {src: null, width: null, height: null, id: null, localize: null},
        children: ["caption", "alt"]
    },
    caption: {
        attrs: {id: null, localize: ["false"]},
        children: ["embedvar", "br", "emph", "item", "link", "switchinline", "variable"]
    },
    alt: {
        attrs: {'xml-lang': null, id: null, localize: ["false"]},
    },
    embedvar: {
        attrs: {href: null, markup: ["keep", "ignore"]},
    },
    br: {
        attrs: {'xml-lang': null, id: null, localize: ["false"]},
        children: ["embedvar", "br", "emph", "item", "link", "switchinline", "variable"]
    },
    emph: {
        children: ["item", "comment", "help-id-missing"]
    },
    item: {
        attrs: {type: null},
    },
    link: {
        attrs: {href: null, name: null, type: null},
        children: ["emph", "item", "variable", "embedvar", "switchinline"]
    },
    switchinline: {
        attrs: {select: null},
        children: ["caseinline", "defaultinline"]
    },
    variable: {
        attrs: {id: null, visibility: ["hidden", "visible"]},
        children: ["ahelp", "embedvar", "br", "emph", "item", "link", "variable", "image", "object", "switchinline"]
    },
    ahelp: {
        attrs: {hid: null, visibility: ["hidden", "visible"]},
        children: ["comment", "embedvar", "br", "emph", "item", "link", "variable"]
    },
    object: {
        attrs: {type: null, id: null, data: null, width: null, height: null},
    },
    bookmark: {
        attrs: {branch: null, 'xml-lang': null, localize: ["false"]},
        children: ["bookmark-value"]
    },
    'bookmark-value': {
        children: ["embedvar"]
    },
    table: {
        attrs: {name: null, width: null, height: null, unit: ["px", "pt"], class: null, id: null, localize: ["false"]},
        children: ["caption", "tablerow"]
    },
    tablerow: {
        attrs: {height: null, unit: ["px", "pt", "cm", "in"], class: null, localize: ["false"]},
        children: ["tablecell"]
    },
    tablecell: {
        attrs: {colspan: null, rowspan: null, width: null, unit: ["px", "pt", "cm", "in", "pct"], class: null, localize: ["false"]},
    },
    list: {
        attrs: {type: ["ordered", "unordered"], startwith: null, format: ["1", "i", "I", "a"], bullet: ["disc", "circle", "square"], localize: ["false"], sorted: ["asc", "desc"]},
        children: ["listitem", "comment"]
    },
    listitem: {
        attrs: {format: ["1", "i", "I", "a"], bullet: ["disc", "circle"], localize: ["false"], class: null},
        children: ["comment", "section", "paragraph", "table", "switch", "embed", "bookmark"]
    },
    sort: {
        attrs: {order: ["asc", "desc"]},
        children: ["section"]
    },
    embed: {
        attrs: {href: null, role: null, level: null},
    },
    switch: {
        attrs: {select: ["sys"], localize: ["false"]},
        children: ["case", "comment", "default"]
    },
    case: {
        attrs: {select: null},
        children: ["paragraph", "table", "comment", "bookmark", "embed", "list", "switch", "section"]
    },
    default: {
        children: ["paragraph", "table", "comment", "bookmark", "embed", "list", "section"]
    },
    title: {
        attrs: {'xml-lang': null, id: null, localize: ["false"]},
    },
};

// And here's the code that provides the auto-completion in the editor

function completeAfter(cm, pred) {
    var cur = cm.getCursor();
    if (!pred || pred()) setTimeout(function() {
        if (!cm.state.completionActive)
            cm.showHint({completeSingle: false});
    }, 100);
    return CodeMirror.Pass;
}

function completeIfAfterLt(cm) {
    return completeAfter(cm, function() {
        var cur = cm.getCursor();
        return cm.getRange(CodeMirror.Pos(cur.line, cur.ch - 1), cur) == "<";
    });
}

function completeIfInTag(cm) {
    return completeAfter(cm, function() {
        var tok = cm.getTokenAt(cm.getCursor());
        if (tok.type == "string" && (!/['"]/.test(tok.string.charAt(tok.string.length - 1)) || tok.string.length == 1)) return false;
        var inner = CodeMirror.innerMode(cm.getMode(), tok.state).state;
        return inner.tagName;
    });
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */