diff --git a/keyterms/keyterms.py b/keyterms/keyterms.py index f1ccf35..0f16c17 100644 --- a/keyterms/keyterms.py +++ b/keyterms/keyterms.py @@ -147,8 +147,10 @@ def update_keyterm_html(self, list, course_id): self.keytermhtml = "" for keyterm in list: div_parent_id = "#allKeytermsList" - keyterm_card_header_id = pydash.camel_case("heading" + keyterm) - keyterm_data_target = pydash.camel_case("collapse" + keyterm) + # remove all non alphanumeric characters and capitalize each word in keyterm. This matches what is being done in keyterms.js + clean_keyterm = ''.join(char for char in keyterm.title() if char.isalnum()) + keyterm_card_header_id = pydash.camel_case("heading" + clean_keyterm) + keyterm_data_target = pydash.camel_case("collapse" + clean_keyterm) keyterm_data_target_hashed = f'#{keyterm_data_target}' keyterm_show = ("show" if list[0] == keyterm else "") cardItem = '
\n' @@ -162,7 +164,7 @@ def update_keyterm_html(self, list, course_id): cardItem += '
\n' cardItem += '
\n' cardItem += '
\n' - cardItem += ' Example Content.\n' + cardItem += ' Error loading content.\n' cardItem += '
\n' cardItem += '
\n' cardItem += '\n' diff --git a/keyterms/static/js/src/keyterms.js b/keyterms/static/js/src/keyterms.js index 603eedc..55b1403 100644 --- a/keyterms/static/js/src/keyterms.js +++ b/keyterms/static/js/src/keyterms.js @@ -6,9 +6,11 @@ function camelize(str) { return str.toLowerCase() // Replaces any - or _ characters with a space - .replace(/[-_]+/g, ' ') + .replace(/[-_/]+/g, ' ') // Removes any non alphanumeric characters .replace(/[^\w\s]/g, '') + // Ensure there are no double spaces after removing characters + .replace(/ /g, ' ') // Uppercases the first character in each group immediately following a space // (delimited by spaces) .replace(/ (.)/g, function($1) { return $1.toUpperCase(); })