Grrrr....cannot add fractions in a fill in the blank

Am trying to create an interactive math video. I have found that if I use a fill-in-the-blank, I cannot have an answer that is a fraction such as 2/3 because I assume the / in a response triggers something different. I hav correctly put in the text for the answer as *2/3* Yet, when you enter the response 2/3 in the blank it comes up as incorrect, but when you select 'show solution' it comes up as the correct answer 2/3.....hmmmmm.

Support for fractions (escape character)
Content types: 
Issue Status: 
Supporter votes Members of the Supporter Network can vote for feature requests. When the supporter network has generated sufficient funding for the top voted feature request it will normally be implemented and released. More about the H5P Supporter Network
otacke's picture

Sorry to hear that you are running into trouble with Fill in the Blanks. The slash (/) is used for separating alternative answers as described when entering the text, so the solution button showing 2/3 means that either 2 or 3 is correct. I assume that fill in the blanks had been created with text in mind, not numbers.

In fact, there's a pull request pending that would offer a workaround using so called regular expressions, but that would really be a "detour". You'd have to write *[[[2\/3]]]*. Anyway, the pull request is still in review and not implemented, and even with it being accepted, there should probably be a more elegant solution that doesn't break old content.

Your suggestions are welcome! 

papi Jo's picture

As otacke says the FITB activity is expecting plain text to be inserted in the blanks. Actually, things would be easier if the original programmer had decided to use the universally accepted character (in computing) for separating alternative elements "|", vertical bar aka pipe character!

As a provisional workaround, you might use that vertical bar for your fractions, of course making it clear to your users that that they have to use it (and HOW to produce that character on their keyboard).

otacke's picture

Is it safe to assume that the separator could be safely changed from / to | using the H5P content upgrade hook (compare e.g. upgrades.js in Interactive Video)? Or do you expect that someone used | within a solution for a blank? Introducing \ as escape character in general would help here, of course, and might be a nice contribution anyway.

papi Jo's picture

If we agree that replacing the forward slash / with a pipe character | to separate alternative solutions in the Blanks library, this would indeed need adding an upgrade rule in the upgrade.js. Since it seems that the use of the forward slash / separator causes a problem only in the case of fractions, I suggest a solution which does not rely on changing the separator. I have tried Otacke's suggestion of using the escape backslash character, but found it impossible to implement in my little search & replace routine. So I propose to use a double forward slash for fractions.

Here is an illustration of how it works for the question creator.

This fraction 8/12 can be simplified as *2//3/4//6* of course. The sum 4 can be obtained with *1+3/2+2/3+1/12//3*.

The first blank will accept "2/3" or "4/6" as correct answers. The second blank will accept "1+3" or  "2+2" or "3+1" or "12/3".

One further problem is when asking for "show solutions", the forward slash is used, which makes fractions undistinguisable!

I suggest replacing the "show solutions" forward slash with a pipe character surrounded with blanks " | " so we have now:

See suggested routine on JSFiddle at

If people agree with my proposal I will pull a request to the H5P github.


tomaj's picture

Hey guys,

I agree that there should definatly be a way to escape the slash. And it should be pretty simple to implement.

I created a Jira task so it can be fixed.

- Tom

tomaj's picture

Hi Joseph and Oliver,

I'm did some refactoring on Drag Text (it has a similar case to this). Some text is parsed, and there are some "special characters" that are used.

Here is the old parsing code (similar to blanks case), and here is the refactored code, where a regex is used to split up the string.

It should be easy use a regex for the Blanks case, but also add an escape character.

What do you think?

- Tom

PS: Look at how much more readable the code is in my refactored example! :)

otacke's picture
papi Jo's picture

Hi Tom,

Yes, regex is probably the best way to go, and also try to have a more general solution than the one I provided. I've cloned the current h5p-drag-text library on my localhost Drupal development folder and switched to branch 'HFP-361-Accessibility'. However, when I try to view an activity created with that branch I get the error message:

Cannot read property 'AriaDrag' of undefined at new DragText (drag-text.js:64).

tomaj's picture

Hi Joseph,

That branch isn't production ready yet, and I'm experimenting with a few things. I need to iron out the problems before I merge to master.

So you probably shouldn't play too much with it. But the TextParser works! :)

- Tom

You made my day!

I was wondering if this feature would be added. I was hoping to use the Fill in the Blank to help assess html </html>. Thank you!

BV52's picture

Hi bjuarez1,

I'm sorry this task is still backlogged and not yet sellected for development.


kymschutz's picture

I would like to ask a blood pressure reading for nurses and doctors.

The Blood Pressure 120/80 does not wor and needs to be split into two entries ie: *120*/*80*

It would be great to allow 120/80 with an escape charactier of some sort...


Hi, I enjoy very much working with H5p, thanks to all developpers, this is a wonderfull Job !

I’m creating exercices to work on formula and improve nowledge in spreadsheets. It’s difficult for pupils to use * in spreadsheet and X in exercice ;  / in spreadsheets and ÷ in exercices.

So I agree, it will be usefull to add an escape character.

On line 724 of blanks.js, there seems to a single line of code that defines this behavior.

// Split up alternatives
var solutions = solution.split('/');

I am not suggesting that making this change would just involve this line, of course, but this seems to be crucial line where the behavior is defined. One might be able to change it locally.

As others have noted above, the choice of the forward slash was simply not a good choice.  A bar, i.e., the character '|' , would be much better because it is consistent with many programming languages that use '|' or '||' to denote some form of OR.   The bar character is seldom used in answers, whereas the forward slash is used all the time in answers (fractions, blood pressure, dates,...). 

It really should be fixed.  Little things like this might seem trivial, but they are not.   The lack of the ability to have any fractions in answers severely limits H5P blanks questions for use in most mathematics or science settings.  People will reject H5P for alternatives and move on.

In addition, I would also advocate for implementing an escape character on top of changing the forward slash to '|'.    That would require a little more coding.

BV52's picture

Hi djabon,

Thank you for the suggestions. I will forward these to the H5P core team.


Currently in the proccess of testing the software and ran into a problem with a fractional answer. It's baffling how easy it is to fix this and yet it has not been, in over six years! This is very big problem although it has not been treated like one, if anyone with access to the code were change a foward slash to a back slash or just about anything else this software would be 10x better. 
Please fix this. 

waiting for an early solution to this issue. would be of great help.

papi Jo's picture

This "bug" was first mentioned back in ... 2017. Now we are in 2024. Please be patient, it might be fixed in 2031; that's only 7 more years to wait.