{"action":"created","issue":{"url":"https://api.github.com/repos/atlassian/commonmark-java/issues/50","repository_url":"https://api.github.com/repos/atlassian/commonmark-java","labels_url":"https://api.github.com/repos/atlassian/commonmark-java/issues/50/labels{/name}","comments_url":"https://api.github.com/repos/atlassian/commonmark-java/issues/50/comments","events_url":"https://api.github.com/repos/atlassian/commonmark-java/issues/50/events","html_url":"https://github.com/atlassian/commonmark-java/issues/50","id":152848686,"number":50,"title":"Disable autoconverting HTML entity references","user":{"login":"md384","id":4070250,"avatar_url":"https://avatars.githubusercontent.com/u/4070250?v=3","gravatar_id":"","url":"https://api.github.com/users/md384","html_url":"https://github.com/md384","followers_url":"https://api.github.com/users/md384/followers","following_url":"https://api.github.com/users/md384/following{/other_user}","gists_url":"https://api.github.com/users/md384/gists{/gist_id}","starred_url":"https://api.github.com/users/md384/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/md384/subscriptions","organizations_url":"https://api.github.com/users/md384/orgs","repos_url":"https://api.github.com/users/md384/repos","events_url":"https://api.github.com/users/md384/events{/privacy}","received_events_url":"https://api.github.com/users/md384/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2016-05-03T18:56:31Z","updated_at":"2016-05-05T23:20:13Z","closed_at":"2016-05-04T17:14:29Z","body":"As the title says, is there a way to disable autoconverting HTML entity references, e.g. `&alpha;` to `α`? I am saving the converted HTML in a DB which is Windows-1252 encoded (can't be changed right now) so having some problems."},"comment":{"url":"https://api.github.com/repos/atlassian/commonmark-java/issues/comments/217307582","html_url":"https://github.com/atlassian/commonmark-java/issues/50#issuecomment-217307582","issue_url":"https://api.github.com/repos/atlassian/commonmark-java/issues/50","id":217307582,"user":{"login":"md384","id":4070250,"avatar_url":"https://avatars.githubusercontent.com/u/4070250?v=3","gravatar_id":"","url":"https://api.github.com/users/md384","html_url":"https://github.com/md384","followers_url":"https://api.github.com/users/md384/followers","following_url":"https://api.github.com/users/md384/following{/other_user}","gists_url":"https://api.github.com/users/md384/gists{/gist_id}","starred_url":"https://api.github.com/users/md384/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/md384/subscriptions","organizations_url":"https://api.github.com/users/md384/orgs","repos_url":"https://api.github.com/users/md384/repos","events_url":"https://api.github.com/users/md384/events{/privacy}","received_events_url":"https://api.github.com/users/md384/received_events","type":"User","site_admin":false},"created_at":"2016-05-05T23:20:13Z","updated_at":"2016-05-05T23:20:13Z","body":"I didn't deal with surrogate pairs, I just put something together that worked for our use-case. \r\n\r\nThat could be useful for others so I'll leave it here but it is basic and hacky and probably won't be enough for most.\r\n\r\n```\r\nprivate static final Pattern sf_htmlEntityPattern = Pattern.compile(\"&(#[xX][a-fA-F0-9]{1,8}|#[0-9]{1,8}|[a-zA-Z][a-zA-Z0-9]{1,31});\");\r\nprivate static final Pattern sf_escapedHtmlEntityPattern = Pattern.compile(\"&amp;(#[xX][a-fA-F0-9]{1,8}|#[0-9]{1,8}|[a-zA-Z][a-zA-Z0-9]{1,31});\");\r\n\r\n/**\r\n   * Escape HTML entities (e.g. &alpha;) as the markdown parser auto-converts to unicode characters.\r\n   * &xxx; escapes to &amp;xxx; then find and replace these using unescapeHtmlEntities.\r\n   *\r\n   * Call escapeHtmlEntities on pre-parsed markdown and unescapeHtmlEntities on renderer html.\r\n   */\r\nprivate static String escapeHtmlEntities(String text) {\r\n  return sf_htmlEntityPattern.matcher(text).replaceAll(\"\\\\\\\\&$1;\");\r\n}\r\n\r\nprivate static String unescapeHtmlEntities(String text) {\r\n  return sf_escapedHtmlEntityPattern.matcher(text).replaceAll(\"&$1;\");\r\n}\r\n```"}}