Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6775713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:56:22+00:00 2026-05-26T15:56:22+00:00

Problem* Given some data (text) which has style applied to it with a loosely

  • 0

Problem*

Given some data (text) which has style applied to it with a loosely defined markup, such as:

The [blower]cat[elower] [weight 15]sat[normal] on the mat.[newline]

Which would ideally be represented as something like:

The <text class="lower">cat</text> <strong>sat</strong> on the mat.<br />

The markup has the following properties:

  • A tag represents an instruction to format text in a given way from that point onward
  • An end tag may exist, but only for a small set of tags. Other tags are linear (see point 1)
  • Each tag has it’s own behaviour, and may affect previously applied tags in different ways
  • Some nesting is implied from the linear tags adding to or overwriting existing styles
  • Metadata may be outside of tags (eg. [beg][xyz]cmd[end1] is all tag related, no content)

Requirements

  • Define rules around tag interaction (eg. A style tag such as [bold] is closed by another style tag such as [normal] or [light])
  • Nesting of some content (tags which do not overwrite as above will nest and break accordingly)
  • Define maps from the well defined in memory representation to some output format

Thoughts

  • Parse into DOM like structure – Attempt to group tags into ‘sets’. When a tag is encountered, close the active tag for that set and open the new one. This produces <tag>content</tag>. Problems around proper nesting and closing/reopening tags so that you dont end up with overlap situations like <b>text<i>text</b>text</i> are annoying but straight forward enough.

How would you set about designing a data structure or method of parsing the content such that a set of rules can aid transformation to a well defined structure?

Alternatively, any suggestions for fields/areas that you would look at when solving this sort of problem?

*Real world problem

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:56:23+00:00Added an answer on May 26, 2026 at 3:56 pm

    This problem is isomorphic (at least as you’ve described it so far) to XML. You have syntax that introduces and ends markup, and it comes mostly in pairs [blower]…[elower] and [weight 15]…[normal] with the occasional standalone [newline].

    So if you know how to build an XML parser with tags, you know how to do this, too.

    If you don’t, you just need a grammar (in EBNF) and a parser generator:

    document =  fragment* ;
    
    fragment = TEXT ;
    fragment = '[blower]' fragment '[elower]' ;
    fragment = '[weight' NATURAL ']' fragment '[normal]' ;
    fragment =  other_start_tag fragment other_end_tag ;
    fragment = '[newline]' ;
    

    This requires a pretty simple lexer, and a pretty simple parser. (See FLEX and YACC as examples).
    You can build your DOM as a set of tree nodes as the parser runs by attaching actions to the grammar rules (See YACC documentation). Many other parser generators will let you build the tree as you parse, too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem: Given a list of strings, find the substring which, if subtracted from the
Here's the jist of the problem: Given a list of sets, such as: [
i'm supposed to write code which when given a text file (source code) as
I'm on Delphi 2009, and my application contains a data module, which has a
I am reading a feed which gives the data with some html tags like
Scenario: I have multiple text boxes in which a user will enter data into
The code below plots some simple x-y data, but it has two problems that
Problem Given the following two tables, I'd like to select all Ids for Posts
First the practical application that led me to the problem: Given a set of
Please help me out with an algorithm for the following problem - Given a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.