Decode html entities in map with pins
This commit is contained in:
parent
b2126eb0ee
commit
b8e0f3662a
@ -19,6 +19,26 @@ function parseCoords(s: string): [number, number] {
|
||||
return s.split(", ").map((x) => parseFloat(x)) as [number, number];
|
||||
}
|
||||
|
||||
function decodeHTMLEntities(text) {
|
||||
var entities = [
|
||||
["amp", "&"],
|
||||
["apos", "'"],
|
||||
["#x27", "'"],
|
||||
["#x2F", "/"],
|
||||
["#39", "'"],
|
||||
["#47", "/"],
|
||||
["lt", "<"],
|
||||
["gt", ">"],
|
||||
["nbsp", " "],
|
||||
["quot", '"'],
|
||||
];
|
||||
|
||||
for (var i = 0, max = entities.length; i < max; ++i)
|
||||
text = text.replace(new RegExp("&" + entities[i][0] + ";", "g"), entities[i][1]);
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
export default class MapWithPins extends Controller {
|
||||
id: string;
|
||||
map: L.Map;
|
||||
@ -70,7 +90,9 @@ export default class MapWithPins extends Controller {
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
const pins = JSON.parse(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-argument
|
||||
this.element.attributes["data-map-with-pins-pins-value"].value
|
||||
decodeHTMLEntities(
|
||||
this.element.attributes["data-map-with-pins-pins-value"].value
|
||||
)
|
||||
) as Pin[];
|
||||
pins.forEach((pin) => this.addPin(pin));
|
||||
this.initiated = true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user