MCPcopy
hub / github.com/Justineo/github-hovercard / fixRepoSlug

Function fixRepoSlug

src/hovercard.js:828–891  ·  view source on GitHub ↗
(html)

Source from the content-addressed store, hash-verified

826
827 // '<span>ecomfe/</span><em>ecomfe</em>.github.io'
828 function fixRepoSlug(html) {
829 let [, leading, content, ending] = html
830 .replace(/\n/g, ' ')
831 .match(/^(\s*)(.+?)(\s*)$/)
832
833 let parts = content
834 .replace(/<\//g, '${END}')
835 .replace(/\//g, '${SLASH}')
836 .replace(/</g, '${BEGIN}')
837 .split('${SLASH}')
838
839 return (
840 leading +
841 parts
842 .map(part => {
843 let [, leading, content, ending] = part.match(/^(\s*)(.+?)(\s*)$/)
844 let marker = /\$\{(\w+)\}/g
845 let open = []
846 let close = []
847 let position
848 let result
849 /* eslint-disable no-cond-assign */
850 while ((result = marker.exec(content))) {
851 position = marker.lastIndex - result[0].length
852 if (result[1] === 'BEGIN') {
853 open.push(position)
854 } else {
855 if (open.length) {
856 open.pop()
857 } else {
858 close.push(position)
859 }
860 }
861 }
862 /* eslint-enable no-cond-assign */
863
864 // <span>user/ -> <span><span>user</span>
865 let begin = 0
866 let end = content.length
867 if (open[0] === 0 || close[0] === 0) {
868 begin = content.indexOf('>') + 1
869 } else if (open.length || close.length) {
870 begin = 0
871 end = open[0] || close[0]
872 }
873
874 content =
875 content.slice(0, end) +
876 '</span>' +
877 content.slice(end, content.length)
878 content =
879 content.slice(0, begin) +
880 '<span data-ghh>' +
881 content.slice(begin, content.length)
882 content = content
883 .replace(/\$\{BEGIN\}/g, '<')
884 .replace(/\$\{END\}/g, '</')
885

Callers 1

extractElemFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected