Skip to content

& selector and css priorities #26

@jtousek

Description

@jtousek
input{
  width: 100px;
  &[type=text]{
    width: 200px;
  }
}

=>

input[type=text] { width:200px; }
input { width:100px; }

That is wrong, because in cases like this, the last value takes the priority. I've tried to implemented some sort of buffer to stop the "input[type=text] { width:200px; }" and send it out after "input { width:100px; }". I'm not very sure about it's effectivity but it works.

Implementation:

    // parse and compile buffer
    function parse($str = null) {
        if ($str) $this->buffer = $str;

        $this->env = array();
        $this->expandStack = array();
        $this->count = 0;
        $this->line = 1;

        $this->buffer = $this->removeComments($this->buffer);
        $this->push(); // set up global scope
        $this->set('__tags', array('')); // equivalent to 1 in tag multiplication

        // trim whitespace on head
        if (preg_match('/^\s+/', $this->buffer, $m)) {
            $this->line  += substr_count($m[0], "\n");
            $this->buffer = ltrim($this->buffer);
        }

    while (false !== ($compiled = $this->chunk())) {
      if (!is_string($compiled))$compiled = '';
      if (!isset($buffer[$this->level-1])) $buffer[$this->level-1] = '';
      $buffer[$this->level-1] .= $compiled;
      if (isset($buffer[$this->level])) {
        $buffer[$this->level-1] .= $buffer[$this->level];
        unset($buffer[$this->level]);
      }
    }

        if ($this->count != strlen($this->buffer)) $this->throwParseError();

        if (count($this->env) > 1)
            throw new exception('parse error: unclosed block');

        //print_r($this->env);
        return $buffer[0];
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions