Skip to content

Commit

Permalink
Text fragments do not work reliably (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
HeikoTheissen authored Jun 14, 2024
1 parent 59f14e8 commit deae611
Show file tree
Hide file tree
Showing 13 changed files with 719 additions and 731 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
10 changes: 9 additions & 1 deletion lib/md2html.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ const filter = require("pandoc-filter");

filter.stdio(function ({ t, c }, format, meta) {
if (t === "Link" && !/^https?:\/\//.test(c[2][0])) {
c[2][0] = c[2][0].replace(/\.md(?=$|#)/, ".html");
if (/^Org\.OData\..*?\.xml#L/.test(c[2][0]))
c[2][0] =
"https://github.com/oasis-tcs/odata-vocabularies/blob/main/vocabularies/" +
c[2][0];
else if (/^com\.sap\..*?\.xml#L/.test(c[2][0]))
c[2][0] =
"https://github.com/SAP/odata-vocabularies/blob/main/vocabularies/" +
c[2][0];
else c[2][0] = c[2][0].replace(/\.md(?=$|#)/, ".html");
return filter.Link(...c);
}
});
12 changes: 6 additions & 6 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 @@ -72,13 +72,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
8 changes: 4 additions & 4 deletions test/csdl2markdown.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,18 +285,18 @@ describe("Non-OASIS Vocabularies", function () {
"## Functions",
"",
'<a name="condense"></a>',
'### [condense](./overload.tst.xml#L11:~:text=<Function%20Name="-,condense,-")',
"### [condense](overload.tst.xml#L11)",
"",
"Overload 1",
"",
"Parameter|Type|Description",
":--------|:---|:----------",
'**[InputSet](./overload.tst.xml#L13:~:text=<Function%20Name="-,condense,-")**|\\[EntityType\\]|**Binding parameter**',
'[&rarr;](./overload.tst.xml#L14:~:text=<Function%20Name="-,condense,-")|\\[EntityType\\]|',
"**[InputSet](overload.tst.xml#L13)**|\\[EntityType\\]|**Binding parameter**",
"[&rarr;](overload.tst.xml#L14)|\\[EntityType\\]|",
"",
"",
'<a name="condense"></a>',
"### [condense](./overload.tst.xml#L16) *(Deprecated)*",
"### [condense](overload.tst.xml#L16) *(Deprecated)*",
"Deprecated in favor of overload 1",
"",
];
Expand Down
Loading

0 comments on commit deae611

Please sign in to comment.