Я получаю текст и список некоторых важных слов из скрипта Python, который я отображаю с помощью колбы в пользовательском интерфейсе.
Я хотел выделить важные ключевые слова в тексте.Что отлично работает, когда я тестирую его на компиляторе w3scool.
<body>
<p id="demo"></p>
<div id="vow_p"></div>
<script>
var vow = "Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I pledge my life and honor to the Night's Watch, for this night and all the nights to come.";
var wordsToBold=["night","watcher"];
function makeBold(input, wordsToBold) {
return input.replace(new RegExp('(\\b)(' + wordsToBold.join('|') + ')(\\b)','ig'), '$1<u><b>$2</u></b>$3');
}
document.getElementById("vow_p").innerHTML = makeBold(vow, wordsToBold);
</script>
</body>
</html>
Тот же код, который я встроил в мое приложение для колб.Здесь проблема только одна, выделение первого ключевого слова остальными ключевыми словами не дает никакого эффекта.Я делаю какую-либо ошибку?
app.py
app = Flask ( name )
@app.route('/')
def index():
return render_template('text-process.html')
в text-process.html
<script>
// var vow = {{ item }};
var someJavaScriptVar = '{{ wordres }}';
var wordsToBold =['reduced'];
function makeBold(input, wordsToBold) {
return input.replace(new RegExp('(\\b)(' + wordsToBold.join(',') + ')(\\b)','ig'), '$1<mark>$2</mark>$3');
}
document.getElementById("vow_p").innerHTML = makeBold(someJavaScriptVar, wordsToBold);
</script>