Coder Social home page Coder Social logo

html_validator's Introduction

HTML Validation with Stacks

You will implement an extended version of the balanced parentheses algorithm that checks whether html tags are balanced. (See chapter 4.7 of the book for details on the balanced parentheses algorithm.)

Learning Objectives:

  1. implement the balanced parenthesis algorithm
  2. practice using HTML
  3. practice using stacks
  4. practice using pytest and test driven development

Background

HTML is how webpages format their content. A simple example is the following code:

Data structures is <strong>the best</strong>!

Which results in text that looks like: Data structures is the best!

The text between angle brackets is called a tag, and tags always come in pairs. The first tag (<strong>) is called an opening tag and the second tag (</strong>) is called a closing tag. Closing tags always have the same text as an opening tag, except that a slash / is added at the very beginning.

There are many html tags that control different formatting options, and they get combined in complex ways to generate the layout of webpages. For example, the <em> tag causes text to be italicized and the <u> tag causes text to be underlined. The HTML:

<u>Data structures</u> is <strong>the <em>best</em></strong>!

results in text that looks like: Data structures is the best!

Large webpages have tens of thousands of html tags in a single file, and it is important to verify that this html is correct. Examples of incorrect html are:

  1. <strong>example (there is no closing </strong> tag)
  2. <strong>python <u>is </strong> awesome </u> (the </strong> closing tag needs to be outside of the </u> tag)

The goal of this assignment is to write a program which can detect these HTML errors.

Real World Application: The World Wide Web Consortium (W3C) is the organization responsible for maintaining the HTML standard. They have a program online at https://validator.w3.org/ which performs HTML validation, and it is used by web developers around the world to improve their webpages. You are implementing a limited version of this program.

Tasks

Complete the following tasks:

  1. Fork the html_validator repo and enable github actions
  2. Update the README.md file so that the test case badges point to your forked repo
  3. Implement the validate_html and _extract_tags functions so that all test cases in tests/test_main.py pass

Extra Credit: HTML Attributes

The function of many HTML tags can be modified by specifying attributes within the opening tag. For example:

This is a hyperlink to <a href="https://izbicki.me">my webpage</a>.

The a tag creates a hyperlink, and the href attribute specifies where the link goes. Notice that the href attribute appears only in the opening tag and not in the closing tag.

The file tests/test_ec.py contains test cases for HTML that includes attributes. If your code successfully passes all of these test cases, then you will get 1 point of extra credit on the assignment. You must pass all of the test cases and get the green extra credit badge in order to get this point.

HINT: You do not need to modify the validate_html function at all. Instead, just modify the _extract_tags function so that it ignores any attributes present in the opening tag.

html_validator's People

Contributors

kevinl0378 avatar mikeizbicki avatar npcrites avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.