J'utilise JavaScript RegExp pour mettre en évidence les recherches dans le contenu HTML.
Pour ce faire, j'utilise :
data.replace( new RegExp("("+search+")", 'g'), "<b id='searchHighlight'>$1</b>" );
donde data
est l'ensemble du contenu HTML et search
est la chaîne de recherche.
Lorsque l'on cherche, par exemple, h
il mettrait en évidence les h dans les mots (the, there, etc...) ainsi que les occurrences dans les balises telles que "<h1 id="title"> Something </h1>"
etc.
Je ne peux pas opter pour une autre approche puisque je dois mettre en évidence le même contenu HTML avec le même style.
J'ai lu des solutions comme :
var input = "a dog <span class='something'> had a </span> and a cat";
// Remove anything tag-like
var temp = input.replace(/<.+?>/g, "");
// Perform the search
var matches = new RegExp(exp, "g").exec(temp);
Mais comme je dois mettre en évidence le texte de la recherche dans le même contenu HTML, je ne peux pas simplement supprimer les balises existantes. Existe-t-il un moyen de faire une recherche par inclusion et exclusion dans RegExp, de sorte que je puisse, par exemple, mettre en évidence h
en "le" con "t<b id='searchHighlight'>h</b>e"
et ne pas permettre "<h1 id="title">Test</h1>"
pour être corrompu ainsi : "<<b id='searchHighlight'>h</b>1 id="title">Test</<b id='searchHighlight'>h</b>1>"
?
Le contenu HTML est statique et ressemble à ceci :
<h1 id="title">Samples</h1>
<div id="content">
<div class="principle">
<h2 id="heading">
PRINCIPLE</h2>
<p>
FDA recognizes that samples are an important part of ensuring that the right drugs are provided to the right patients. Under the Prescription Drug Marketing Act (PDMA), a sales representative is permitted to provide prescription drug samples to eligible healthcare professionals (HCPs). In order for BMS to provide this service, representatives must strictly abide by all applicable compliance standards pertaining to the distribution of samples.</p></div>
<h2 id="heading">
WHY DOES IT MATTER?</h2>
<p>
The Office of Inspector General (OIG) recognizes that samples can have monetary value to HCPs and, when used improperly, may have implications under the Federal False Claims Act and the Federal Anti-kickback Act. To minimize risk of such liability, the OIG requires the clear and conspicuous labeling of individual samples as units that cannot be sold. BMS and its business partners label every sample package to meet this requirement. Additionally, the HCP signature statement acknowledges that the samples will not be sold, billed or provided to family members or friends.</p>
<h2 id="heading">
WHO IS YOUR SMaRT PARTNER?</h2>
<p>
SMaRT is an acronym for “Samples Management and Representatives Together”. A SMaRT Partner has a thorough understanding of BMS sample requirements and is available to assist the field with any day-to-day policy or procedure questions related to sample activity. A SMaRT Partner will also:</p>
<ul>
<li style="margin-left:22pt;"> Monitor your adherence to BMS’s sample requirements.</li>
<li style="margin-left:22pt;"> Act as a conduit for sharing sample compliance issues and best practices.</li>
<li style="margin-left:22pt;"> Respond to day-to-day sample accountability questions within two business days of receipt.</li>
</ul>
<p>
Your SMaRT Partner can be reached at 888-475-2328, Option 3.</p>
<h2 id="heading">
BMS SAMPLE ACCOUNTABILITY POLICIES & PROCEDURES</h2>
<p>
It is the responsibility of each sales representative to read, understand and follow the BMS Field Sample Accountability Procedures, USPSM-SOP-101. The basic expectations are:</p>
<ul>
<li style="margin-left:22pt;"> Transmit all sample activity by communicating your tablet to the host server on a <strong>daily</strong> basis.</li>
<li style="margin-left:22pt;"> Maintain a four to six week inventory of samples rather than excessive, larger inventories that are more difficult to manage and increase your risk of non-compliance.</li>
<li style="margin-left:22pt;"> Witness all HCP’s signatures to confirm request and receipt of samples.</li>
</ul>
</div>
Les contenus sont tous dispersés et ne se trouvent pas dans une seule étiquette. La manipulation du DOM n'est donc pas une solution pour moi.