Skip to content

Commit

Permalink
Text fragments do not work reliably
Browse files Browse the repository at this point in the history
  • Loading branch information
HeikoTheissen committed Jun 14, 2024
1 parent 59f14e8 commit e877b5b
Show file tree
Hide file tree
Showing 11 changed files with 721 additions and 736 deletions.
22 changes: 1 addition & 21 deletions lib/csdl2markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ module.exports.csdl2markdown = function (filename, csdl, referenced = {}) {

const over = {};
overloads.forEach((o) => {
if (over[o.$$name]) o.$$parent = "overload";
over[o.$$name] = true;
lines.push("");
lines.push('<a name="' + o.$$name + '"></a>');
Expand All @@ -243,7 +242,6 @@ module.exports.csdl2markdown = function (filename, csdl, referenced = {}) {
(o.$Parameter || []).forEach(function (p, i) {
let desc;
p.$$name = p.$Name;
p.$$parent = o.$$parent || o;
const depr = deprecated(p);
if (depr) desc = depr.Description;
else desc = descriptionInTable(p);
Expand Down Expand Up @@ -273,7 +271,6 @@ module.exports.csdl2markdown = function (filename, csdl, referenced = {}) {
});
if (o.$ReturnType) {
o.$ReturnType.$$name = "&rarr;";
o.$ReturnType.$$parent = o.$$parent || o;
lines.push(
sourceLink(o.$ReturnType) +
"|" +
Expand Down Expand Up @@ -360,7 +357,6 @@ module.exports.csdl2markdown = function (filename, csdl, referenced = {}) {
lines.push(":------------|:----------");
values.forEach((v) => {
v.$$name = v.Value;
v.$$parent = typeDefinition;
lines.push(
sourceLink(v) +
experimentalOrDeprecated(v) +
Expand Down Expand Up @@ -447,7 +443,6 @@ module.exports.csdl2markdown = function (filename, csdl, referenced = {}) {
const p = type[name];
p.$$name = name;
p.$$filename = type.$$filename;
p.$$parent = type;
let desc = "";
for (let t = type; t[name] && !desc; t = modelElement(t.$BaseType)) {
desc = descriptionInTable(t[name]);
Expand Down Expand Up @@ -538,7 +533,6 @@ module.exports.csdl2markdown = function (filename, csdl, referenced = {}) {
}

members.forEach((m) => {
m.$$parent = type;
lines.push(
sourceLink(m) +
experimentalOrDeprecated(m) +
Expand Down Expand Up @@ -645,7 +639,6 @@ module.exports.csdl2markdown = function (filename, csdl, referenced = {}) {
if (allowedValues.length > 0) text.push("<dl>Allowed values:");
allowedValues.forEach((v) => {
v.$$name = v.Value;
v.$$parent = "nofragment";
let allowedValue = "<dt>" + sourceLink(v) + experimentalOrDeprecated(v);
const description = descriptionInTable(v);
if (description) allowedValue += "<dd>" + description;
Expand Down Expand Up @@ -686,26 +679,13 @@ module.exports.csdl2markdown = function (filename, csdl, referenced = {}) {
*/
function sourceLink(modelElement, parent = false) {
const line = modelElement[sourceLine];
let textFragment;
if (
modelElement.$$parent !== "overload" &&
modelElement.$$parent !== "nofragment"
)
textFragment = modelElement.$Kind ? modelElement : modelElement.$$parent;
return (
(line ? "[" : "") +
(modelElement.$Abstract || parent ? "*" : "") +
modelElement.$$name +
(modelElement.$Abstract || parent ? "*" : "") +
(line
? "](./" +
(modelElement.$$filename || filename) +
"#L" +
line +
(textFragment
? `:~:text=<${textFragment.$Kind}%20Name="-,${textFragment.$$name},-"`
: "") +
")"
? "](" + (modelElement.$$filename || filename) + "#L" + line + ")"
: "")
);
}
Expand Down
19 changes: 12 additions & 7 deletions lib/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ fs.readdirSync(vocabFolder)
colors.red(
`${vocabFolder + filename}:${e.parser.line}:${e.parser.column}: ${
e.message
}`
)
}`,
),
);
process.exitCode = 1;
return;
Expand All @@ -45,7 +45,7 @@ fs.readdirSync(vocabFolder)
}
fs.writeFileSync(
vocabFolder + vocab + ".json",
JSON.stringify(json, omitLineNumbers, 4)
JSON.stringify(json, omitLineNumbers, 4),
);
});

Expand All @@ -55,7 +55,12 @@ for (const [filename, csdl] of Object.entries(vocabs)) {
const vocab = filename.substring(0, filename.lastIndexOf("."));
console.log(vocab + ".md");

const markdown = lib.csdl2markdown(filename, csdl, vocabs);
const markdown = lib.csdl2markdown(
"https://github.com/oasis-tcs/odata-vocabularies/blob/main/vocabularies/" +
filename,
csdl,
vocabs,
);
fs.writeFileSync(vocabFolder + vocab + ".md", markdown.join("\n"));
}

Expand All @@ -72,13 +77,13 @@ fs.readdirSync(exampleFolder)
const json = csdl.xml2json(xml, { strict: true });
fs.writeFileSync(
exampleFolder + example + ".json",
JSON.stringify(json, null, 4)
JSON.stringify(json, null, 4),
);
} catch (e) {
console.error(
colors.red(
`${xmlfile}:${e.parser.line}:${e.parser.column}: ${e.message}`
)
`${xmlfile}:${e.parser.line}:${e.parser.column}: ${e.message}`,
),
);
process.exitCode = 1;
}
Expand Down
Loading

0 comments on commit e877b5b

Please sign in to comment.