Tips for coloring just the letters and excluding the Bengali Kar symbol

The Bengali language consists of 40 consonants, including ক, খ, গ, ঘ, ঙ, চ, ছ, জ, ঝ, ঞ, and more. Additionally, there are 10 vowels in the form of Kars, such as া, ি, ী, ু, ূ, ৃ, ে, ৈ, ো, and ৌ.

My goal is to highlight the first consonant in a word with a different color, but the vowels should also be colored.


Expected Result

https://i.sstatic.net/elRhC.png


Code Sample

@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+Bengali:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2057474854601110100e0e191010">[email protected]</a>&display=swap');
p {
  font-family: "Noto Serif Bengali", serif;
  font-variation-settings: "wdth" 100;
}

mark {
  color: red;
  background: transparent;
}
<p>
  <mark>ক</mark>াগজ<br/>
  <mark>ঠ</mark>েলাগাড়ি<br/>
  <mark>দ</mark>োয়েল<br/>
</p>


Update

I found an interesting idea from @etuardu. I created a CSS-only solution based on @etuardu's suggestion. However, as mentioned by @Peter Constable, this solution works only when the base consonant in a cluster remains unchanged. It may not work in cases like গুরু or শুরু.

@import url('https://fonts.googleapis.com/css2?family=Noto+Serif:Bengali:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2f5848475b6f1e1f1f0101161f1f">[email protected]</a>&display=swap');
p {
  font-family: "Noto Serif Bengali", serif;
  font-size: 24px;
}

span[data-mark] {
  position: relative;
}

span[data-mark]::after {
  content: attr(data-mark);
  color: red;
  position: absolute;
  left: 0;
  top: 0;
}

span[data-mark-offset]::after {
  left: 0.39em;
}
<p>
  <span data-mark="ক">কাগজ</span><br/>
  <span data-mark="ঠ" data-mark-offset>ঠেলাগাড়ি</span><br/>
  <span data-mark="দ" data-mark-offset>দোয়েল</span><br/>
  <span data-mark="র">রূপ</span><br/>
  <span data-mark="স">সুজন</span><br/>
  <span data-mark="গ">গুরু</span><br/>
  <span data-mark="শ">শুরু</span><br/>
</p>

Answer №1

When dealing with consonant-vowel combinations in a text layout engine, complex interactions occur within clusters. The challenge arises from the fact that the relationship between characters in a string and the glyphs in a font used to display that string is not always a straightforward 1:1 correlation.

For instance, certain Bangla or Assamese fonts may render 'ga + u' as shown in https://i.sstatic.net/htqCw.png. This poses a difficulty for the layout engine in determining which parts of which glyphs should be highlighted in red.

In theory, a layout could choose a single glyph within a cluster to highlight in red, which might work for some combinations like ঠো. However, in cases where a cluster like গু is displayed as a single glyph, highlighting only the consonant may not suffice.

While it's feasible for a layout engine to apply different coloring to individual glyphs within a cluster, this approach may not extend to all types of text styling. Selecting different fonts, for example, would be problematic as the display of elements within a cluster relies on data within the font regarding how glyphs interact, including the positioning of mark glyphs in relation to base glyphs. In practice, many layout engines treat clusters as indivisible units for styling purposes.

Answer №2

It has been noted by others that combinations of letters like these are treated as a distinct cluster, making it challenging to achieve your objective easily.

One approach could involve utilizing JavaScript and CSS to superimpose a <mark> on top of a <span> at a specific location. By using em as a unit of measurement, you can ensure precise positioning regardless of the font size.

While this solution may not be perfect, it could be suitable for certain scenarios.

document.querySelectorAll('[data-mark]').forEach(e => {
  const mark = document.createElement('mark')
  mark.innerText = e.dataset.mark
  mark.style.left = e.dataset.markOffset
  e.appendChild(mark)
})
@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+Bengali:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4235252a36027372726c6c7b7272">[email protected]</a>&display=swap');
p {
  font-family: "Noto Serif Bengali", serif;
  font-size: 24px;
}

mark {
  color: red;
  background: transparent;
}

span[data-mark] {
  position: relative;
}

span[data-mark] mark {
  position: absolute;
  left: 0;
  top: 0;
}
<p>
  <span data-mark="ক">কাগজ</span><br/>
  <span data-mark="ঠ" data-mark-offset=".39em">ঠেলাগাড়ি</span><br/>
  <span data-mark="দ" data-mark-offset=".39em">দোয়েল</span><br/>
</p>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Entity designation experiencing operational difficulties

Having trouble converting my HTML to XHTML. Whenever I replace the greater than sign with &gt;, my if statement stops working properly. The same issue occurs when replacing the ampersand with & and the less than sign with <. Even CDATA isn' ...

interactive form fields updating using javascript

Hey there! I'm a beginner in web development and currently facing a challenge. I have a form with 2 fields generated by one drop-down menu. I've managed to generate one field, but struggling to get the other due to my limited knowledge. I just ne ...

Tips for displaying the initial slide when a tab is loaded on a multi-tab webpage

I have a total of four tabs, with the first tab containing a slideshow. On page load, I am successfully triggering the first tab, but for some reason, the first slide in the slideshow within that tab is displaying a blank image. I'm struggling to find ...

Is there a way to showcase the search outcomes of employee information stored in my text document using PHP?

i was tasked with creating a PHP file that could search for an employee's ID number and display the results on the same page from a text file. The expected output should look like this: Expected Output (results on the same page): Search Employee Rec ...

What is the best way to enlarge an image while keeping it contained within a card using Bootstrap?

Is it possible to create a visually appealing card similar to the image provided using Bootstrap 5.3.3 and HTML on a website? https://i.sstatic.net/OH4U0.png ...

Adjustable ember count within Intercom HTML using Selenium and Python

My goal is to automate tasks at my workplace, but I am facing some challenges. Due to the lack of admin access on my work Intercom App, I have resorted to using Selenium. I need to input "Hey" into the chat box on Intercom and send the message successfull ...

What are the steps to ensure that data retrieved from an API is accurately displayed in a table?

My current goal is to collect data from the crypto compare API and display it in a table format. Although I am able to generate the necessary elements and append them to the table body, I am facing an unusual issue. Each time I use a for loop to iterate th ...

Obtaining an identification using JQuery for content that is constantly changing

I am currently developing dynamic content tabs using PHP, with one of the objects being a datatable within the tab. In order to define the ID via PHP, I use the following code: PHP: echo '<table class="table table-striped table-bordered table-hov ...

Angular Flot Chart Resizing: A Guide to Dynamic Chart S

I have successfully integrated a Flot chart into my HTML using an Angular directive. Here is how it looks: <flot id="placeholder" dataset="dataset" options="options" height="300px" width="100%" style="width:100%;" ng-disabled="graphLoading" ng-class="{ ...

How can the parent div's height be determined by the child div when using position: absolute?

I am struggling with setting the height of a parent div that contains a nested child div with absolute positioning. The child div has a fixed height of 652px, but I cannot seem to get the parent div to match this height. I have tried adjusting the clear an ...

How can I use AJAX to read an image file and display it on a Canvas?

Is there a way to read an image from my server using Ajax and then display it on Canvas? I am aware that this can be achieved by using normal image tags and canvas draw methods, as shown below: <img id="myImage" src="./ColorTable.PNG" style="display:n ...

Incorporating interactive maps into an AngularJS web application

I've been attempting to integrate Google Maps into my AngularJS application, using the script tag below: <script src="https://maps.googleapis.com/maps/api/js?key=[MySecretKeyHere]&callback=initMap" async defer></script> I found this ...

Strange Phenomenon: Website Appears Enlarged When Accessed through Server

Similar Question: Why does my website appear smaller on a live server than when deployed locally? After reviewing the answer to the similar question linked above, I still found myself facing the same issue with no resolution. My problem is that the webpa ...

Bootswatch is causing the Bootstrap tooltip feature to malfunction

Could someone help me figure out why my tooltip isn't functioning properly? The HTML Code in Question: <div class="form-check"> <label class="form-check-label" > <input type="radio" class="form-check-input" name= ...

Creating a radio button along with a submit button that redirects to a different local HTML file

Can someone please help with this code? I'm trying to redirect to the value of each radio button when it's clicked. Any guidance or JavaScript code would be greatly appreciated. Thank you. I've tried multiple solutions but none of them seem ...

Transitioning from a CSS box-shadow effect to an inset-box shadow on hover

Have you ever encountered the challenge of transitioning from a normal box-shadow to an inset box-shadow? I'm curious if this is the reason why my transition isn't working, or if there's another issue with my code. What steps should I take i ...

What is the correct way to reset the styling of a web browser element, such as a <button>?

I have come across many sources advising me to reset HTML by manually resetting numerous individual properties, as demonstrated here: https://css-tricks.com/overriding-default-button-styles/ Another approach I discovered in CSS is simply using: button: {a ...

The issue of the background image not expanding to cover the entire page when resized is problematic

Hello there, I'm currently working on making my website responsive and I've run into a problem with GIF images. No matter what I do, they just won't fill the entire page. When I try to make them smaller, it leaves white spaces at the top and ...

Creating a Three-Row Table with Material-UI and React

I am looking to achieve a layout similar to the one shown in the image below: I want to construct a table with three rows, where the third row is positioned below the first and second rows, and the width of the third row is equal to the combined width of t ...

In order to format my text, I must locate a specific character and encompass the text following it with HTML tags

When working with a list generated in Jekyll, I came across the need to emphasize certain words using strong tags. My solution was to incorporate a delimiter into the process. <li>100g of |sugar</li> This would transform into: <li>100g ...