Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Caracteres especiais não interpretados em código inline #13

Open
rubinhos opened this issue Oct 10, 2019 · 2 comments
Open

Caracteres especiais não interpretados em código inline #13

rubinhos opened this issue Oct 10, 2019 · 2 comments
Labels
beginner bug Something isn't working easy pick good first issue Good for newcomers hacktoberfest Hacktoberfest help wanted Extra attention is needed javascript node npm portinariui PortinariUI thf typescript

Comments

@rubinhos
Copy link
Contributor

Ao converter um arquivo markdown com código inline os caracteres especiais não são interpretados pela aplicação Angular.

Exemplo:
<list-item></list-item> é convertido para &lt;list-item&gt;&lt; e não é interpretado.

@rubinhos rubinhos added bug Something isn't working help wanted Extra attention is needed good first issue Good for newcomers hacktoberfest Hacktoberfest beginner easy pick javascript typescript node npm portinariui PortinariUI thf labels Oct 10, 2019
@Renato66
Copy link

Peguei a biblioteca undescore e tirei algumas coisas de la para montar esse arquivo, que faz/desfaz a conversão

var _ = {}
var nativeKeys = Object.keys

_.isObject = function(obj) {
  var type = typeof obj;
  return type === 'function' || type === 'object' && !!obj;
};

_.keys = function(obj) {
  if (!_.isObject(obj)) return [];
  if (nativeKeys) return nativeKeys(obj);
  var keys = [];
  for (var key in obj) if (has(obj, key)) keys.push(key);
  // Ahem, IE < 9.
  if (hasEnumBug) collectNonEnumProps(obj, keys);
  return keys;
};

_.invert = function(obj) {
  var result = {};
  var keys = _.keys(obj);
  for (var i = 0, length = keys.length; i < length; i++) {
    result[obj[keys[i]]] = keys[i];
  }
  return result;
};

var escapeMap = {
  '&': '&amp;',
  '<': '&lt;',
  '>': '&gt;',
  '"': '&quot;',
  "'": '&#x27;',
  '`': '&#x60;'
};

var unescapeMap = _.invert(escapeMap);

// Functions for escaping and unescaping strings to/from HTML interpolation.
var createEscaper = function(map) {
  var escaper = function(match) {
    return map[match];
  };
  // Regexes for identifying a key that needs to be escaped.
  var source = '(?:' + _.keys(map).join('|') + ')';
  var testRegexp = RegExp(source);
  var replaceRegexp = RegExp(source, 'g');
  return function(string) {
    string = string == null ? '' : '' + string;
    return testRegexp.test(string) ? string.replace(replaceRegexp, escaper) : string;
  };
};

_.escape = createEscaper(escapeMap);
_.unescape = createEscaper(unescapeMap);
_.escape('<list-item></list-item>')
// "&lt;list-item&gt;&lt;/list-item&gt;"

_.unescape('&lt;list-item&gt;&lt;/list-item&gt;')
// "<list-item></list-item>"

@Renato66
Copy link

caso precise de mais caracteres é só mapear na variavel escapeMap

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beginner bug Something isn't working easy pick good first issue Good for newcomers hacktoberfest Hacktoberfest help wanted Extra attention is needed javascript node npm portinariui PortinariUI thf typescript
Projects
None yet
Development

No branches or pull requests

2 participants