Как обрабатывать пользовательские теги HTML с помощью JavaScript - PullRequest
0 голосов
/ 07 ноября 2018

Мне дают HTML с пользовательскими тегами для записей глоссария, например: а также Я думал, что смогу автоматически заменить это на a href, однако, это не работает, как ожидалось.

Исходя из ответов, которые я до сих пор немного изменил, теперь у меня есть

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
  $( "glo" ).each(function(index){  
	var x = ( $( this ).attr("name") );
		link = document.createElement("a"); 
		link.setAttribute('href', '../../QA-C/Messages/Glossary.html#' + x);
		var y = ($( this).text());
				$(this).html('');
				link.innerHTML = y;
				$("glo")[index].prepend(link);
        });
    });
});
 
</script>
</head>
<body>

<h2>This is a heading</h2>

   <p>
            <p>
            <glo name ="size_t">size_t</glo> is defined by a typedef in the standard library header files <code class="nm">&lt;stdio.h&gt;, &lt;stddef.h&gt;, &lt;stdlib.h&gt;, &lt;string.h&gt;</code> and <code class="nm">&lt;time.h&gt;</code>.
</p>
        <p>
QA C has an option (-intrinsictype), which allows the type associated with <i>size_t</i> to be configured.
Message 0040 is generated if a <i>typedef</i> encountered in the source code is not consistent with this configured type.
</p>
        <p>
The <glo name="QA_C.Standard.Library.header.files">QA_C.Standard.Library.header.files</glo> use an implicit macro, <i>PRQA_SIZE_T</i>, when declaring the type of <i>size_t</i>.
This macro is automatically defined in the QA C environment to reflect the configuration option setting.
If you are using your own header files to define <i>size_t</i>, you should ensure that QA C is configured to be consistent with this typedef.
</p>

</p>
<p>
<glo name="size_t">size for size_t</glo> some text to test
</p>

<button>Click me</button>

</body>
</html>

так что это работает, но я уверен, что должен быть более элегантный способ сделать это.

...