JSFiddle - React, Tailwind, and code Playground
HTML
<div id="article-detail-desc">
<p>أعرب الرئيس الأميركي باراك أوباما في اتصال مع نظيره اللبناني ميشال سليمان عن قلقه مما وصفه دور حزب الله النشيط والمتزايد في سوريا وقتاله إلى جانب النظام السوري.</p>
<p>وذكر البيت الأبيض في بيان أن أوباما ناقش مع سليمان التزامهما المشترك بالحفاظ على استقرار لبنان وسيادته وأمنه، لا سيما فيما يتعلق بالصراع الدائر حاليا في سوريا.</p>
</div>
CSS
p {margin:10px;}
#ArticleContent { width:500px; height:100%; text-align:justify; background-color:#fff;}
.ad-keyword-selected
{
color:#990044;
text-decoration:none;
}
.ui-tooltip, .arrow:after {
background: #fff;
border: 1px solid #f5f5f5;
}
.ui-tooltip {
padding: 10px 20px;
color: #333333;
border-radius: 10px;
font: normal 12px Georgia,"Times New Roman",Times,serif;
text-transform: uppercase;
box-shadow: 0 0 3px #333333;
}
.arrow {
width: 70px;
height: 16px;
overflow: hidden;
position: absolute;
left: 50%;
margin-left: -35px;
bottom: -16px;
}
.arrow.top {
top: -16px;
bottom: auto;
}
.arrow.left {
left: 20%;
}
.arrow:after {
content: "";
position: absolute;
left: 20px;
top: -20px;
width: 25px;
height: 25px;
box-shadow: 6px 5px 9px -9px black;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
-o-transform: rotate(45deg);
tranform: rotate(45deg);
}
.arrow.top:after {
bottom: -20px;
top: auto;
}
JavaScript
(function() {
// Our keywords. There are lots of ways you can produce
// this map, here I've just done it literally
var keywords = {
"الهدف": true,
"طهران": true,
"سيما": true,
"حاليا": true
};
// Loop through all our paragraphs (okay, so we only have two)
$("p").each(function() {
var $this, text;
// We'll use jQuery on `this` more than once,
// so grab the wrapper
$this = $(this);
// Get the text of the paragraph
// Note that this strips off HTML tags, a
// real-world solution might need to loop
// through the text nodes rather than act
// on the full text all at once
text = $this.text();
// Do the replacements
// These character classes just use the primary
// Arabic range of U+0600 to U+06FF, you may
// need to add others.
text = text.replace(
/([\u0600-\u06ff]+)([^\u0600-\u06ff]+)?/g,
replacer);
// Update the paragraph
$this.html(text);
});
// Our replacer. We define it separately rather than
// inline because we use it more than once
function replacer(m, c0, c1) {
// Is the word in our keywords map?
if (keywords[c0]) {
// Yes, wrap it
c0 = '<a href="#">' + c0 + '</a>';
}
return c0 + c1;
}
})();